gee

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 25 Imported by: 3

README


Build Status codecov Go Report Card
GoDoc

Gee is base on gin framework

Usage

import "github.com/goapt/gee"

router := gee.Default()

router.GET("/", func(c *gee.Context) error {
    return c.String("hello")
})

Proto API tools

go install github.com/goapt/gee/cmd/protoc-gen-go-gee-errors
go install github.com/goapt/gee/cmd/protoc-gen-go-gee-http

generate error

    protoc --proto_path=. --proto_path=../third_party \
    --go_out=paths=source_relative:. \
    --go-gee-errors_out=paths=source_relative:. \
    ./proto/demo/v1/error_reason.proto

generate http

    protoc --proto_path=. --proto_path=../third_party \
    --go_out=paths=source_relative:. \
    --go-gee-http_out=paths=source_relative:. \
    ./proto/demo/v1/demo.proto

For example: /example

Documentation

Index

Constants

View Source
const (
	// DebugMode indicates gin mode is debug.
	DebugMode = gin.DebugMode
	// ReleaseMode indicates gin mode is release.
	ReleaseMode = gin.ReleaseMode
	// TestMode indicates gin mode is test.
	TestMode = gin.TestMode
)
View Source
const (
	JsonContentType = "application/json; charset=utf-8"
	FormContentType = "application/x-www-form-urlencoded; charset=utf-8"
	XmlContentType  = "application/xml; charset=utf-8"
	TextContentType = "text/plain; charset=utf-8"
)

Variables

View Source
var ErrorHandler = func(c *Context, err error) error {
	c.Abort()
	return c.String(err.Error())
}

Functions

func CreateTestContext added in v1.4.0

func CreateTestContext(w http.ResponseWriter) (*Context, *Engine)

func DebugRoute

func DebugRoute(router *Engine, path ...string)

func DebugWithRouteGroup added in v1.4.1

func DebugWithRouteGroup(router *RouterGroup)

func HandlerFunc

func HandlerFunc(h Handler) gin.HandlerFunc

func SetDebugToken added in v1.4.1

func SetDebugToken(token string)

func SetMode added in v1.5.1

func SetMode(value string)

Types

type AuthFunc added in v1.6.0

type AuthFunc = func(req *http.Request) error

type Client added in v1.6.0

type Client struct {
	Endpoint string
	// contains filtered or unexported fields
}

Client is an HTTP client.

func NewClient added in v1.6.0

func NewClient(client *http.Client, endpoint string, opts ...ClientOption) *Client

func (*Client) Invoke added in v1.6.0

func (c *Client) Invoke(ctx context.Context, method, path string, args any, reply any) error

type ClientOption added in v1.6.0

type ClientOption func(c *clientOptions)

func WithAuthorization added in v1.6.0

func WithAuthorization(fn AuthFunc) ClientOption

func WithErrorDecoder added in v1.6.0

func WithErrorDecoder(errorDecoder ErrorDecoderFunc) ClientOption

func WithTimeout added in v1.6.0

func WithTimeout(t time.Duration) ClientOption

type Context

type Context struct {
	*gin.Context

	Response *Response
	// contains filtered or unexported fields
}

func (*Context) BindJSON

func (c *Context) BindJSON(obj any) error

func (*Context) GetBody added in v1.1.3

func (c *Context) GetBody() ([]byte, error)

GetBody read body data and restore request body data

func (*Context) JSON

func (c *Context) JSON(data any) error

func (*Context) Redirect

func (c *Context) Redirect(location string) error

func (*Context) RequestId

func (c *Context) RequestId() string

func (*Context) ShouldBindBodyJSON added in v1.1.3

func (c *Context) ShouldBindBodyJSON(obj any) error

func (*Context) ShouldBindJSON

func (c *Context) ShouldBindJSON(obj any) error

func (*Context) ShouldBindQuery added in v1.7.0

func (c *Context) ShouldBindQuery(obj any) error

func (*Context) ShouldBindUri added in v1.7.0

func (c *Context) ShouldBindUri(obj any) error

func (*Context) Status

func (c *Context) Status(status int)

func (*Context) String

func (c *Context) String(format string, values ...any) error

func (*Context) XML added in v1.4.0

func (c *Context) XML(data any) error

func (*Context) YAML added in v1.6.0

func (c *Context) YAML(data any) error

type Engine added in v1.3.0

type Engine struct {
	*gin.Engine
	RouterGroup
}

func Default added in v1.3.0

func Default() *Engine

func New added in v1.3.0

func New() *Engine

func (*Engine) NoRoute added in v1.3.0

func (e *Engine) NoRoute(handlers ...Handler)

func (*Engine) ServeHTTP added in v1.3.0

func (e *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Engine) Use added in v1.3.0

func (e *Engine) Use(middleware ...Handler) IRoutes

type ErrorDecoderFunc added in v1.6.0

type ErrorDecoderFunc = func(ctx context.Context, res *http.Response) error

type H added in v1.3.0

type H map[string]any

H is a shortcut for map[string]interface{}

func (H) MarshalXML added in v1.3.0

func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML allows type H to be used with xml.Marshal.

type Handler added in v1.6.0

type Handler = func(c *Context) error

func Wrap added in v1.3.0

func Wrap(h gin.HandlerFunc) Handler

func WrapH added in v1.4.1

func WrapH(h http.Handler) Handler

type IRoutes added in v1.3.0

type IRoutes interface {
	Use(...Handler) IRoutes
	Any(string, ...Handler) IRoutes
	GET(string, ...Handler) IRoutes
	POST(string, ...Handler) IRoutes
	DELETE(string, ...Handler) IRoutes
	PATCH(string, ...Handler) IRoutes
	PUT(string, ...Handler) IRoutes
	OPTIONS(string, ...Handler) IRoutes
	HEAD(string, ...Handler) IRoutes
}

IRoutes defines all router handle interface.

type Response

type Response struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

func (*Response) Before added in v1.6.0

func (w *Response) Before(fn func(w *Response))

Before is a function which will be called before the response is written to the client.

func (*Response) Body added in v1.6.0

func (w *Response) Body() []byte

func (*Response) Write added in v1.6.0

func (w *Response) Write(b []byte) (int, error)

func (*Response) WriteString added in v1.6.0

func (w *Response) WriteString(s string) (int, error)

type RouterGroup added in v1.3.0

type RouterGroup struct {
	*gin.RouterGroup
}

func (*RouterGroup) Any added in v1.3.0

func (r *RouterGroup) Any(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) DELETE added in v1.3.0

func (r *RouterGroup) DELETE(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) GET added in v1.3.0

func (r *RouterGroup) GET(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) Group added in v1.3.0

func (r *RouterGroup) Group(relativePath string, handlers ...Handler) *RouterGroup

func (*RouterGroup) HEAD added in v1.3.0

func (r *RouterGroup) HEAD(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) Handle added in v1.4.0

func (r *RouterGroup) Handle(method string, relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) OPTIONS added in v1.3.0

func (r *RouterGroup) OPTIONS(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) PATCH added in v1.3.0

func (r *RouterGroup) PATCH(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) POST added in v1.3.0

func (r *RouterGroup) POST(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) PUT added in v1.3.0

func (r *RouterGroup) PUT(relativePath string, handlers ...Handler) IRoutes

func (*RouterGroup) Use added in v1.3.0

func (r *RouterGroup) Use(middleware ...Handler) IRoutes

type TestRequest added in v1.6.0

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

func NewTestRequest added in v1.6.0

func NewTestRequest(url string, handlers ...Handler) *TestRequest

func NewTestRequestWithPath added in v1.6.0

func NewTestRequestWithPath(path, url string, handlers ...Handler) *TestRequest

func (*TestRequest) BeforeHook added in v1.6.0

func (r *TestRequest) BeforeHook(fn func(req *http.Request))

func (*TestRequest) Form added in v1.6.0

func (r *TestRequest) Form(values *url.Values) (*TestResponse, error)

func (*TestRequest) Get added in v1.6.0

func (r *TestRequest) Get() (*TestResponse, error)

func (*TestRequest) JSON added in v1.6.0

func (r *TestRequest) JSON(data any) (*TestResponse, error)

func (*TestRequest) Post added in v1.6.0

func (r *TestRequest) Post(contentType string, body io.Reader) (*TestResponse, error)

func (*TestRequest) XML added in v1.6.0

func (r *TestRequest) XML(body string) (*TestResponse, error)

type TestResponse added in v1.6.0

type TestResponse struct {
	*httptest.ResponseRecorder
}

func (*TestResponse) GetBody added in v1.6.0

func (r *TestResponse) GetBody() []byte

func (*TestResponse) GetBodyString added in v1.6.0

func (r *TestResponse) GetBodyString() string

func (*TestResponse) GetJson added in v1.6.0

func (r *TestResponse) GetJson() gjson.Result

func (*TestResponse) GetJsonPath added in v1.6.0

func (r *TestResponse) GetJsonPath(path string) gjson.Result

Directories

Path Synopsis
cmd
proto
Package proto defines the protobuf codec.
Package proto defines the protobuf codec.
xml
nolint:gomnd
nolint:gomnd
example module
middleware

Jump to

Keyboard shortcuts

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