service

package module
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 8 Imported by: 17

README

Release License Go Report Card GoDoc Discord

taubyte/http

An HTTP library meant to speed up creating complex http services.

Installation

The import path for the package is github.com/taubyte/http.

To install it, run:

go get github.com/taubyte/http

License

Please see the LICENSE file for details.

Help

Find us on our Discord

Maintainers

  • Samy Fodil @samyfodil
  • Sam Stoltenberg @skelouse
  • Tafseer Khan @tafseer-khan
  • Aron Jalbuena @arontaubyte

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Upgrader = websocket.Upgrader{
		ReadBufferSize:  1024,
		WriteBufferSize: 1024,
		CheckOrigin: func(r *http.Request) bool {
			return true
		},
	}
	ShutdownGracePeriod = 3 * time.Second
)

Functions

This section is empty.

Types

type AssetsDefinition

type AssetsDefinition struct {
	Host                  string
	Path                  string
	Vars                  Variables
	Scope                 []string
	Auth                  RouteAuthHandler
	FileSystem            afero.Fs
	Directory             string
	SinglePageApplication bool

	BeforeServe func(w http.ResponseWriter)
}

type Context

type Context interface {
	HandleWith(handler Handler) error
	HandleAuth(Handler) error
	HandleCleanup(Handler) error
	Request() *http.Request
	Writer() http.ResponseWriter
	ParseBody(obj interface{}) error

	RawResponse() bool
	SetRawResponse(val bool)

	Variables() map[string]interface{}
	SetVariable(key string, val interface{})

	Body() []byte
	SetBody([]byte)

	GetStringVariable(key string) (string, error)
	GetStringArrayVariable(key string) ([]string, error)
	GetStringMapVariable(key string) (map[string]interface{}, error)
	GetIntVariable(key string) (int, error)
}

type Handler

type Handler func(ctx Context) (interface{}, error)

type HeadlessAssetsDefinition

type HeadlessAssetsDefinition struct {
	FileSystem            afero.Fs
	Directory             string
	SinglePageApplication bool

	BeforeServe func(w http.ResponseWriter)
}

type LowLevelDefinition

type LowLevelDefinition struct {
	Path       string
	PathPrefix string
	Handler    func(w http.ResponseWriter, r *http.Request)
}

type PermanentRedirect

type PermanentRedirect Redirect

type RawData

type RawData struct {
	ContentType string
	Data        []byte
}

type RawRouteDefinition

type RawRouteDefinition struct {
	Host        string
	Path        string
	PathPrefix  string
	Vars        Variables
	Scope       []string
	Auth        RouteAuthHandler
	Handler     Handler
	RawResponse bool
}

type RawStream

type RawStream struct {
	ContentType string
	Stream      io.ReadCloser
}

type Redirect

type Redirect string

type RouteAuthHandler

type RouteAuthHandler struct {
	Validator Handler
	GC        Handler
}

type RouteDefinition

type RouteDefinition struct {
	Host        string
	Path        string
	Vars        Variables
	Scope       []string
	Auth        RouteAuthHandler
	Handler     Handler
	RawResponse bool
}

type Service

type Service interface {
	Context() context.Context
	Start()
	Stop()
	Wait() error
	Error() error
	/********************************/
	GET(*RouteDefinition)
	PUT(*RouteDefinition)
	POST(*RouteDefinition)
	DELETE(*RouteDefinition)
	PATCH(*RouteDefinition)
	ALL(*RouteDefinition)

	Raw(*RawRouteDefinition) *mux.Route
	LowLevel(*LowLevelDefinition) *mux.Route

	WebSocket(*WebSocketDefinition)

	ServeAssets(*AssetsDefinition)

	AssetHandler(*HeadlessAssetsDefinition, Context) (interface{}, error)
	LowLevelAssetHandler(*HeadlessAssetsDefinition, http.ResponseWriter, *http.Request) error

	GetListenAddress() (*url.URL, error)
}

type TemporaryRedirect

type TemporaryRedirect Redirect

type Variables

type Variables struct {
	Required []string
	Optional []string
}

type WebSocketDefinition

type WebSocketDefinition struct {
	Host       string
	Path       string
	Vars       Variables
	Scope      []string
	Auth       RouteAuthHandler
	NewHandler func(ctx Context, conn *websocket.Conn) WebSocketHandler
}

type WebSocketHandler

type WebSocketHandler interface {
	In()
	Out()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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