Skip to content

package webapi

import "kaijuengine.com/editor/webapi"

Constants

VersionPrefix

"/v1"

HelpPath

"/help"

DefaultPort

1337

Variables

ErrMissingAPIKey

errors.New("webapi: missing API key")

ErrDuplicateRoute

errors.New("webapi: duplicate route")

ErrInvalidRoute

errors.New("webapi: invalid route")

Functions

Address

func Address(port int32) string

MustRegister[T any]

func MustRegister[T any](handler Endpoint[T])

Register[T any]

func Register[T any](handler Endpoint[T]) error

Types

Config

struct

type Config struct {
    Enabled bool
    Port    int32
    APIKey  string
}

Endpoint

interface

type Endpoint[T any] interface {
    Routes() []Route
    ServeEditorWebAPI(editor T, w http.ResponseWriter, r *http.Request)
}

HelpResponse

struct

type HelpResponse struct {
    Version   string  `json:"version"`
    Endpoints []Route `json:"endpoints"`
}

Route

struct

type Route struct {
    Method      string `json:"method"`
    Path        string `json:"path"`
    Description string `json:"description,omitempty"`
    Example     string `json:"example,omitempty"`
}

Server

struct

type Server[T any] struct {
    // Has unexported fields.
}

New[T any]

func New[T any](editor T) *Server[T]

Server.Apply

func (s *Server[T]) Apply(config Config) error

Server.Close

func (s *Server[T]) Close(ctx context.Context) error

Server.ServeHTTP

func (s *Server[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)