api

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

README

quick start

1.eg.helloword

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

2.eg.login

api.GET(func(username,password string) interface{} {
      return "hello word"
}, "/login")
api.StartService(":8011")
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(":8011")
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(":8011")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GET  = httpM(stdhttp.MethodGet)
	POST = httpM(stdhttp.MethodPost)
	PUT  = httpM(stdhttp.MethodPut)

	// 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
)

Functions

func ApiHttp

func ApiHttp(rw http.ResponseWriter, req *http.Request, service func() *Service)

func PackApi

func PackApi()

func PackApiWithPath

func PackApiWithPath(exePath func() *string)

func SetExecPath

func SetExecPath(path *string)

func SetLogTrimPrefix added in v0.0.2

func SetLogTrimPrefix(prefix string)

func StartService

func StartService(addr string)

func StartTLSService

func StartTLSService(addr string, caFile, certFile, keyFile string)

Types

type Service

type Service struct{}

func (*Service) ServeHTTP

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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