common

package module
v0.0.0-...-a57500f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2021 License: MIT Imports: 25 Imported by: 7

README

common

Packages common, common/app, common/filesystem contains shared (between host app and plugins) parts of code

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrResponseProcessorNotFound = errors.New("ResponseProcessor not found")

Functions

func CacheParams

func CacheParams(params ...interface{}) string

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the configuration directory

func ExpandTilde

func ExpandTilde(path string) (string, error)

ExpandTilde replaces tilde symbol in path by user home directory

func HomeDir

func HomeDir() (string, error)

HomeDir returns user home directory

func NewHttpHost

func NewHttpHost(router *httprouter.Router, options ...*plugins.Options) (plugins.Host, error)

NewHttpHost creates plugins.Host instance for HttpPlugins to connect

func ZipFileHandler

func ZipFileHandler(zc *ZipContainer, f RequestTemplateDataFunc, prefix ...string) http.HandlerFunc

ZipFileHandler returns a http.HandlerFunc for serving files from zip container

Types

type CacheMap

type CacheMap interface {
	Put(key string, params string, value string)
	Get(key string, params string) (string, error)
	HasKey(key string, params string) bool
	Remove(key string, params ...string)
}

func NewCacheMap

func NewCacheMap() CacheMap

type FullResponse

type FullResponse struct {
	Status int
	Hdr    http.Header
	Body   []byte
	// contains filtered or unexported fields
}

FullResponse is marshallable struct for http.ResponseWriter

func NewFullResponse

func NewFullResponse() *FullResponse

func (*FullResponse) Header

func (r *FullResponse) Header() http.Header

Header implements http.ResponseWriter.Header() method

func (*FullResponse) HttpResponse

func (r *FullResponse) HttpResponse() (*http.Response, error)

HttpResponse returns a http.Response struct, parsed from common.FullResponse

func (*FullResponse) Write

func (r *FullResponse) Write(data []byte) (int, error)

Write implements http.ResponseWriter.Write() method

func (*FullResponse) WriteHeader

func (r *FullResponse) WriteHeader(s int)

WriteHeader implements http.ResponseWriter.WriteHeader() method

func (*FullResponse) WriteTo

func (r *FullResponse) WriteTo(res http.ResponseWriter) error

WriteTo writes completed FullResponse into http.ResponseWriter

type HttpPlugin

type HttpPlugin interface {
	Router() *httprouter.Router
	GET(path string, handle httprouter.Handle)
	HEAD(path string, handle httprouter.Handle)
	POST(path string, handle httprouter.Handle)
	PUT(path string, handle httprouter.Handle)
	PATCH(path string, handle httprouter.Handle)
	DELETE(path string, handle httprouter.Handle)
	Call(serviceMethod string, args interface{}, reply interface{}) error
	Logger() *log.Logger
	Serve()
	OnServe(func())
	OnStop(func())
}

HttpPlugin is used for serving HTTP requests from main application.

func NewHttpPlugin

func NewHttpPlugin(pluginName string, root string, options ...*plugins.Options) (HttpPlugin, error)

NewHttpPlugin creates HttpPlugin instance

type Opts

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

type RPCHttpHandler

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

RPCHttpHandler implements Http Handler RPC service

func (*RPCHttpHandler) Handle

func (rh *RPCHttpHandler) Handle(req *Request, _ *int) error

type RPCHttpResponseHandler

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

func (*RPCHttpResponseHandler) WriteData

func (p *RPCHttpResponseHandler) WriteData(data ResponseData, cnt *int) error

func (*RPCHttpResponseHandler) WriteHeader

func (p *RPCHttpResponseHandler) WriteHeader(header ResponseHeader, _ *int) error

type Request

type Request struct {
	ReqId      RequestId
	RemoteAddr string
	Buf        []byte
}

Request is marshallable struct for http.Request

func NewRequest

func NewRequest(req *http.Request, body bool) (*Request, error)

NewRequest creates new common.Request, parsed from http.Request

func (*Request) HttpRequest

func (a *Request) HttpRequest() (*http.Request, error)

HttpRequest returns a http.Request struct, parsed from common.Request

type RequestId

type RequestId int

RequestId is marshallable request id

type RequestTemplateDataFunc

type RequestTemplateDataFunc func(*http.Request) interface{}

RequestTemplateDataFunc is a request-depended callback function for retrieve template's render params

type ResponseData

type ResponseData struct {
	ReqId RequestId
	Data  []byte
}

ResponseData is marshallable struct for http.ResponseWriter.Write method

type ResponseHeader

type ResponseHeader struct {
	ReqId  RequestId
	Status int
	Header http.Header
}

ResponseHeader is marshallable struct for http.ResponseWriter.WriteHeader method

type TemplateDataFunc

type TemplateDataFunc func() interface{}

TemplateDataFunc is a callback function for retrieve template's render params

type ZipContainer

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

ZipContainer is a container for zip data implements io.Closer

func NewZipContainer

func NewZipContainer(zipData string, options ...*Opts) (*ZipContainer, error)

func OpenZipContainer

func OpenZipContainer(filename string, options ...*Opts) (*ZipContainer, error)

noinspection GoUnusedExportedFunction

func (*ZipContainer) Close

func (zc *ZipContainer) Close() error

Close implements io.Closer Close() method Closes zip file when ZipContainer created from zip file

func (*ZipContainer) Walk

func (zc *ZipContainer) Walk(root string, walkFn filepath.WalkFunc) error

Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient.

type ZipFileSystem

type ZipFileSystem interface {
	http.FileSystem
	FromTemplate(name string) bool
	FromImmutable(name string) bool
	FromStaticCompressed(name string, method string) bool
	FileContent(name string) ([]byte, error)
}

func NewZipFileSystem

func NewZipFileSystem(zc *ZipContainer, f ...TemplateDataFunc) ZipFileSystem

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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