http_json

package
v0.0.0-...-5872c39 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: GPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PrintDebug = false

Functions

This section is empty.

Types

type APIHandler

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

func NewAPIHandler

func NewAPIHandler(hm *gorpc.HandlersManager, cache cache.ICache, callbacks APIHandlerCallbacks) *APIHandler

func (*APIHandler) CanServe

func (h *APIHandler) CanServe(req *http.Request) bool

func (*APIHandler) IsDebug

func (h *APIHandler) IsDebug(req *http.Request) bool

func (*APIHandler) ServeHTTP

func (h *APIHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*APIHandler) SetTimeout

func (h *APIHandler) SetTimeout(timeout time.Duration) *APIHandler

type APIHandlerCallbacks

type APIHandlerCallbacks struct {
	OnInitCtx             func(ctx context.Context, req *http.Request) context.Context
	OnError               func(ctx context.Context, w http.ResponseWriter, req *http.Request, resp interface{}, err *gorpc.CallHandlerError)
	OnPanic               func(ctx context.Context, w http.ResponseWriter, r interface{}, trace []byte, req *http.Request)
	OnStartServing        func(ctx context.Context, req *http.Request)
	OnEndServing          func(ctx context.Context, req *http.Request, startTime time.Time)
	OnBeforeWriteResponse func(ctx context.Context, w http.ResponseWriter)
	OnSuccess             func(ctx context.Context, req *http.Request, handlerResponse interface{}, startTime time.Time)
	On304                 func(ctx context.Context, req *http.Request)
	On404                 func(ctx context.Context, req *http.Request)
	OnCacheHit            func(ctx context.Context, entry *cache.CacheEntry)
	OnCacheMiss           func(ctx context.Context)
	GetCacheKey           func(ctx context.Context, req *http.Request, params interface{}) []byte
}

type Definitions

type Definitions map[string]interface{}

type HttpSessionResponse

type HttpSessionResponse struct {
	Result string       `json:"result"`
	Data   interface{}  `json:"data"`
	Error  string       `json:"error"`
	Debug  *debug.Debug `json:"debug,omitempty"`
}

func (HttpSessionResponse) MarshalEasyJSON

func (v HttpSessionResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (HttpSessionResponse) MarshalJSON

func (v HttpSessionResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*HttpSessionResponse) UnmarshalEasyJSON

func (v *HttpSessionResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*HttpSessionResponse) UnmarshalJSON

func (v *HttpSessionResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Info

type Info struct {
	Version     string `json:"version"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

type Items

type Items struct {
	Schema
}

type JsonParametersGetter

type JsonParametersGetter struct {
	Req         io.ReadCloser
	MaxFormSize int64
	// contains filtered or unexported fields
}

func (*JsonParametersGetter) Fork

func (p *JsonParametersGetter) Fork(values map[string]interface{}) interface{}

func (*JsonParametersGetter) GetBool

func (p *JsonParametersGetter) GetBool(path []string, name string) (bool, error)

func (*JsonParametersGetter) GetByte

func (p *JsonParametersGetter) GetByte(path []string, name string) (uint8, error)

func (*JsonParametersGetter) GetFloat32

func (p *JsonParametersGetter) GetFloat32(path []string, name string) (float32, error)

func (*JsonParametersGetter) GetFloat64

func (p *JsonParametersGetter) GetFloat64(path []string, name string) (float64, error)

func (*JsonParametersGetter) GetInt

func (p *JsonParametersGetter) GetInt(path []string, name string) (int, error)

func (*JsonParametersGetter) GetInt16

func (p *JsonParametersGetter) GetInt16(path []string, name string) (int16, error)

func (*JsonParametersGetter) GetInt32

func (p *JsonParametersGetter) GetInt32(path []string, name string) (int32, error)

func (*JsonParametersGetter) GetInt64

func (p *JsonParametersGetter) GetInt64(path []string, name string) (int64, error)

func (*JsonParametersGetter) GetInt8

func (p *JsonParametersGetter) GetInt8(path []string, name string) (int8, error)

func (*JsonParametersGetter) GetString

func (p *JsonParametersGetter) GetString(path []string, name string) (string, error)

func (*JsonParametersGetter) GetUint

func (p *JsonParametersGetter) GetUint(path []string, name string) (uint, error)

func (*JsonParametersGetter) GetUint16

func (p *JsonParametersGetter) GetUint16(path []string, name string) (uint16, error)

func (*JsonParametersGetter) GetUint32

func (p *JsonParametersGetter) GetUint32(path []string, name string) (uint32, error)

func (*JsonParametersGetter) GetUint64

func (p *JsonParametersGetter) GetUint64(path []string, name string) (uint64, error)

func (*JsonParametersGetter) GetUint8

func (p *JsonParametersGetter) GetUint8(path []string, name string) (uint8, error)

func (*JsonParametersGetter) IsExists

func (p *JsonParametersGetter) IsExists(path []string, name string) bool

func (*JsonParametersGetter) Parse

func (p *JsonParametersGetter) Parse() error

func (*JsonParametersGetter) TraverseMap

func (p *JsonParametersGetter) TraverseMap(path []string, name string, h func(k string, v interface{}) error) (bool, error)

func (*JsonParametersGetter) TraverseSlice

func (p *JsonParametersGetter) TraverseSlice(path []string, name string, h func(i int, v interface{}) error) (bool, error)

type MultipartGetter

type MultipartGetter struct {
	ParametersGetter
}

func NewMultipartGetter

func NewMultipartGetter(req *http.Request) (*MultipartGetter, error)

func (*MultipartGetter) Parse

func (g *MultipartGetter) Parse() error

Add upload files to Params like a string params["{inputName}"] = string(file) params["filename_{inputName}"] = string(filename)

Example:

type MyData struct {
    File     string `key:"my_file"`
    Filename string `key:"filename_my_file"`
}

type Operation

type Operation struct {
	Tags        []string               `json:"tags,omitempty"`
	Summary     string                 `json:"summary"`
	Description string                 `json:"description"`
	Consumes    []string               `json:"consumes,omitempty"`
	Produces    []string               `json:"produces,omitempty"`
	Parameters  []*Parameter           `json:"parameters,omitempty"`
	Responses   Responses              `json:"responses,omitempty"`
	Security    []*SecurityRequirement `json:"security,omitempty"`
	ExtraData   interface{}            `json:"-"`
}

type Parameter

type Parameter struct {
	Schema
	// used for body parameter (in == "body")
	BodySchema       *Schema `json:"schema,omitempty"`
	Name             string  `json:"name"`
	In               string  `json:"in"`
	Description      string  `json:"description"`
	Required         bool    `json:"required"`
	CollectionFormat string  `json:"collectionFormat,omitempty"`
}

type ParametersGetter

type ParametersGetter struct {
	Req *http.Request
	// contains filtered or unexported fields
}

func (*ParametersGetter) Fork

func (p *ParametersGetter) Fork(values map[string]interface{}) interface{}

func (*ParametersGetter) GetBool

func (pg *ParametersGetter) GetBool(path []string, name string) (bool, error)

func (*ParametersGetter) GetByte

func (pg *ParametersGetter) GetByte(path []string, name string) (uint8, error)

func (*ParametersGetter) GetFloat32

func (pg *ParametersGetter) GetFloat32(path []string, name string) (float32, error)

func (*ParametersGetter) GetFloat64

func (pg *ParametersGetter) GetFloat64(path []string, name string) (float64, error)

func (*ParametersGetter) GetInt

func (pg *ParametersGetter) GetInt(path []string, name string) (int, error)

func (*ParametersGetter) GetInt16

func (pg *ParametersGetter) GetInt16(path []string, name string) (int16, error)

func (*ParametersGetter) GetInt32

func (pg *ParametersGetter) GetInt32(path []string, name string) (int32, error)

func (*ParametersGetter) GetInt64

func (pg *ParametersGetter) GetInt64(path []string, name string) (int64, error)

func (*ParametersGetter) GetInt8

func (pg *ParametersGetter) GetInt8(path []string, name string) (int8, error)

func (*ParametersGetter) GetString

func (pg *ParametersGetter) GetString(path []string, name string) (string, error)

func (*ParametersGetter) GetUint

func (pg *ParametersGetter) GetUint(path []string, name string) (uint, error)

func (*ParametersGetter) GetUint16

func (pg *ParametersGetter) GetUint16(path []string, name string) (uint16, error)

func (*ParametersGetter) GetUint32

func (pg *ParametersGetter) GetUint32(path []string, name string) (uint32, error)

func (*ParametersGetter) GetUint64

func (pg *ParametersGetter) GetUint64(path []string, name string) (uint64, error)

func (*ParametersGetter) GetUint8

func (pg *ParametersGetter) GetUint8(path []string, name string) (uint8, error)

func (*ParametersGetter) IsExists

func (pg *ParametersGetter) IsExists(path []string, name string) bool

func (*ParametersGetter) Parse

func (pg *ParametersGetter) Parse() error

func (*ParametersGetter) TraverseMap

func (p *ParametersGetter) TraverseMap(path []string, name string, h func(k string, v interface{}) error) (bool, error)

func (*ParametersGetter) TraverseSlice

func (p *ParametersGetter) TraverseSlice(path []string, name string, h func(i int, v interface{}) error) (bool, error)

type PathItem

type PathItem map[string]*Operation

type Properties

type Properties map[string]*Schema

type Response

type Response struct {
	Description string  `json:"description"`
	Schema      *Schema `json:"schema"`
}

type Responses

type Responses map[string]*Response

type Schema

type Schema struct {
	Ref                  string     `json:"$ref,omitempty"`
	Type                 string     `json:"type,omitempty"`
	Description          string     `json:"description,omitempty"`
	Required             []string   `json:"required,omitempty"`
	Items                *Items     `json:"items,omitempty"`
	Properties           Properties `json:"properties,omitempty"`
	AdditionalProperties *Schema    `json:"additionalProperties,omitempty"`
}

type SecurityDefinitions

type SecurityDefinitions map[string]*SecurityScheme

SecurityDefinitions security definitions

type SecurityRequirement

type SecurityRequirement map[string][]string

SecurityRequirement security requirement

type SecurityScheme

type SecurityScheme struct {
	Type        string   `json:"type"`
	Description string   `json:"description,omitempty"`
	Name        string   `json:"name"`
	In          string   `json:"in"`
	Xtensions   []string `json:"x-extensions,omitempty"`
}

SecurityScheme security scheme

type Swagger

type Swagger struct {
	SpecVersion         string              `json:"swagger"`
	Info                Info                `json:"info"`
	BasePath            string              `json:"basePath"`
	Host                string              `json:"host,omitempty"`
	Schemes             []string            `json:"schemes,omitempty"`
	Consumes            []string            `json:"consumes,omitempty"`
	Produces            []string            `json:"produces,omitempty"`
	Paths               map[string]PathItem `json:"paths"`
	Tags                []Tag               `json:"tags,omitempty"`
	Definitions         Definitions         `json:"definitions,omitempty"`
	SecurityDefinitions SecurityDefinitions `json:"securityDefinitions,omitempty"`
}

func GenerateSwaggerJSON

func GenerateSwaggerJSON(hm *gorpc.HandlersManager, host string, callbacks SwaggerJSONCallbacks) (*Swagger, error)

type SwaggerJSONCallbacks

type SwaggerJSONCallbacks struct {
	OnPrepareBaseInfoJSON func(info *Info)
	OnPrepareHandlerJSON  func(path string, data *Operation)
	Process               func(swagger *Swagger)
	TagName               func(path string) string
}

SwaggerJSONCallbacks is struct for callbacks describing

type SwaggerJSONHandler

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

func NewSwaggerJSONHandler

func NewSwaggerJSONHandler(hm *gorpc.HandlersManager, apiPort uint16, callbacks SwaggerJSONCallbacks) *SwaggerJSONHandler

func (*SwaggerJSONHandler) ServeHTTP

func (h *SwaggerJSONHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Tag

type Tag struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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