server

package
v0.0.0-...-f4167b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Data Action = "data"
	Api  Action = "api"
	Test Action = "test"

	GET     Method = "GET"
	POST    Method = "POST"
	OPTIONS Method = "OPTIONS"
)

Variables

This section is empty.

Functions

func Accept

func Accept(ctx context.Context, r *http.Request) ([]byte, int, error)

func Read

func Read(r *http.Request, debug bool) (string, error)

func ReadJson

func ReadJson(r *http.Request, debug bool, v interface{}) (string, error)

Types

type Action

type Action string

type Control

type Control struct {
	Status    Status
	Type      string
	Interrupt bool
	Cancel    context.CancelFunc
	Reaction  chan struct{}
}

Control allows for controlling the flow of the action

func NewController

func NewController(s Status, t string) *Control

func (*Control) AllowInterrupt

func (a *Control) AllowInterrupt() *Control

AllowInterrupt signifies that this action can be interrupted

func (*Control) WithCancel

func (a *Control) WithCancel(cancel context.CancelFunc) *Control

WithCancel assigns a cancel context to the action

type Handler

type Handler func(ctx context.Context, r *http.Request) ([]byte, int, error)

type Method

type Method string

type Route

type Route struct {
	Action    Action
	Interrupt bool
	Path      string
	Method    Method
	Exec      Handler
}

func Live

func Live() Route

func NewRoute

func NewRoute(method Method, action Action) *Route

func (*Route) AllowInterrupt

func (r *Route) AllowInterrupt() *Route

func (*Route) Create

func (r *Route) Create() Route

func (*Route) Handler

func (r *Route) Handler(exec Handler) *Route

func (*Route) Key

func (r *Route) Key() string

func (*Route) WithPath

func (r *Route) WithPath(path string) *Route

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(name string, port int) *Server

func (*Server) Add

func (s *Server) Add(route ...Route) *Server

Add adds the given routes to the server

func (*Server) AddRoute

func (s *Server) AddRoute(method Method, action Action, path string, exec Handler) *Server

AddRoute adds the given routes to the server

func (*Server) Debug

func (s *Server) Debug()

Debug sets the server to debug mode

func (*Server) Run

func (s *Server) Run() error

Run starts the server

type Status

type Status int

Status defines the status of the request

const (
	// Start defines a request has started
	Start Status = iota + 1
	// Finish defines the finishing of a request
	Finish
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL