api

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

README

quick start

1.eg.helloword

api.GET(func() interface{} {
      return "hello word"
}, "/hello")
api.StartService(api.WithListen(":8080"))

2.eg.login

api.GET(func(username,password string) interface{} {
      return "hello word"
}, "/login")
api.StartService(api.WithListen(":8080"))
curl --location --request GET 'http://127.0.0.1:8011/login?username=alloce&password=123456'
upload file
api.POST(func(reader multipart.Reader) interface{} {
	form, _ := reader.ReadForm(0)
	fHeader := form.File["file"][0]
	f, _ := fHeader.Open()
	bytes,_:=ioutil.ReadAll(f)
	return bytes
}, "/fileUpload")
api.StartService(api.WithListen(":8080"))
curl --location --request GET 'http://127.0.0.1:8011/fileUpload' \
--form 'file=@"/C:/Users/Administrator/Downloads/README.MD"'

download file

api.GET(func() interface{} {
	f, _ := os.Open("C:/Users/Administrator/api/README.MD")
	return api.NewStream(f)
}, "/download")
api.StartService(api.WithListen(":8080"))
go build -gcflags all=-N -l

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HEAD    = core.HttpM(stdhttp.MethodHead, def.DefaultContext)
	GET     = core.HttpM(stdhttp.MethodGet, def.DefaultContext)
	POST    = core.HttpM(stdhttp.MethodPost, def.DefaultContext)
	PUT     = core.HttpM(stdhttp.MethodPut, def.DefaultContext)
	PATCH   = core.HttpM(stdhttp.MethodPatch, def.DefaultContext)
	DELETE  = core.HttpM(stdhttp.MethodDelete, def.DefaultContext)
	OPTIONS = core.HttpM(stdhttp.MethodOptions, def.DefaultContext)

	// RegisterErrorHandler error handler
	RegisterErrorHandler = http.RegisterErrorHandler

	// AddHttpHandle http handler
	AddHttpHandle = http.AddHttpHandle

	// RegisterTypeMapper type handler
	RegisterTypeMapper = call.RegisterTypeMapper

	// RegisterReturnHandler register handler
	RegisterReturnHandler = http.RegisterReturnHandler

	NewStream = rettypes.NewStream

	Html     = rettypes.NewHtml
	HtmlView = rettypes.HtmlView

	// Static static web
	Static = http.DefaultStatic.HandleStatic

	NewRedirect = rettypes.NewRedirect

	NewResp = rettypes.NewResp
)

Functions

func StartService

func StartService(ops ...Optional) error

func StartTLSService

func StartTLSService(ops ...Optional) error

Types

type MiddlewareOps added in v0.1.0

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

func AddRoutes added in v0.1.0

func AddRoutes(os ...def.Option) *MiddlewareOps

func (*MiddlewareOps) Middleware added in v0.1.0

func (m *MiddlewareOps) Middleware(mw ...def.MiddleWare) *MiddlewareOps

func (*MiddlewareOps) Swagger added in v0.1.0

func (o *MiddlewareOps) Swagger(opsFn func(swagger def.SwaggerSecurity)) *MiddlewareOps

func (*MiddlewareOps) WithPrefix added in v0.1.0

func (m *MiddlewareOps) WithPrefix(...def.MiddleWare) *MiddlewareOps

type Optional added in v0.1.0

type Optional func(conf *ServerConfig)

func WithCa added in v0.1.0

func WithCa(caPEMBlock []byte) Optional

func WithListen added in v0.1.0

func WithListen(s string) Optional

func WithTLS added in v0.1.0

func WithTLS(certPEMBlock, keyPEMBlock []byte) Optional

func WithTLSFile added in v0.1.0

func WithTLSFile(certFile, keyFile string) Optional

type ServerConfig added in v0.1.0

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

func (*ServerConfig) AddExclude added in v0.1.0

func (c *ServerConfig) AddExclude(pkg ...string)

func (*ServerConfig) AddIncludeRegex added in v0.1.0

func (c *ServerConfig) AddIncludeRegex(regex ...string)

func (*ServerConfig) Dwarf added in v0.1.0

func (c *ServerConfig) Dwarf() *dwarf.DwarfMaker

func (*ServerConfig) Listen added in v0.1.0

func (c *ServerConfig) Listen() string

func (*ServerConfig) LoadPath added in v0.1.0

func (c *ServerConfig) LoadPath() *string

func (*ServerConfig) SetDwarfMaker added in v0.1.0

func (c *ServerConfig) SetDwarfMaker(dwarf *dwarf.DwarfMaker)

func (*ServerConfig) SetDwarfMode added in v0.1.0

func (c *ServerConfig) SetDwarfMode(mode dwarf.FilterMode)

func (*ServerConfig) SetExePath added in v0.1.0

func (c *ServerConfig) SetExePath(path string)

func (*ServerConfig) SetListen added in v0.1.0

func (c *ServerConfig) SetListen(ser string)

type ServerMain added in v0.1.0

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

func NewServer added in v0.1.0

func NewServer(pool *def.MethodsPools) *ServerMain

func (*ServerMain) Maker added in v0.1.0

func (ad *ServerMain) Maker() *dwarf.DwarfMaker

func (*ServerMain) ServeHTTP added in v0.1.0

func (ad *ServerMain) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Directories

Path Synopsis
kit
ws
test
r
ssl

Jump to

Keyboard shortcuts

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