webkit

package module
v0.0.0-...-2dad845 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 16 Imported by: 0

README

go_webkit

Convenient web toolkit for go

包含功能

  • form 请求
  • json 请求
  • 文件上传/下载请求
  • 结构体反射式路由
  • http基准测试
  • 请求设置token
  • 普通函数路由
  • 请求cookies设置

Todo

  • 简单ORM
  • 数据库连接工具
  • 身份验证
  • 日志管理
  • 集成swagger

Documentation

Index

Constants

View Source
const (
	ContentType_Form = "application/x-www-form-urlencoded"
	ContentType_JSON = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context = *gin.Context

Context 类型别名

type File_Info

type File_Info struct {
	Field  string
	Path   string
	Params map[string]string
}

File_Info 发送文件类型

type Form

type Form map[string]interface{}

Form 表单类型

type Method

type Method string

Method http方法类型

const DELETE Method = "DELETE"
const GET Method = "GET"
const OPTIONS Method = "OPTIONS"
const PATCH Method = "PATCH"
const POST Method = "POST"
const PUT Method = "PUT"

func NewMethod

func NewMethod(v string) Method

NewMethod Method构建函数

func (Method) String

func (me Method) String() string

type WebBenchmark

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

WebBenchmark 基准测试类型

func NewWebBenchmark

func NewWebBenchmark(cli *WebClient) *WebBenchmark

NewWebBenchmark 构建基准测试函数

func (*WebBenchmark) RunSingleAPI

func (me *WebBenchmark) RunSingleAPI(tps int, rounds int, interval time.Duration, req func(*WebClient, int) error) benchmark.BenchmarkCount

Run single API 单个API基准测试

type WebClient

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

WebClient web请求辅助工具

func NewWebClient

func NewWebClient(host string) *WebClient

NewWebClient WebClient构造函数

func (*WebClient) DownloadFile

func (me *WebClient) DownloadFile(relativePath string, savePath string,
	params Form, handles ...responseHandle) error

DownloadFile 文件下载方法

func (*WebClient) Form_DELETE

func (me *WebClient) Form_DELETE(relativePath string, params Form,
	handles ...responseHandle) ([]byte, error)

Form_DELETE 表单delete

func (*WebClient) Form_GET

func (me *WebClient) Form_GET(relativePath string, params Form,
	handles ...responseHandle) ([]byte, error)

Form_GET 表单get

func (*WebClient) Form_POST

func (me *WebClient) Form_POST(relativePath string, params Form,
	handles ...responseHandle) ([]byte, error)

Form_POST 表单post

func (*WebClient) Form_PUT

func (me *WebClient) Form_PUT(relativePath string, params Form,
	handles ...responseHandle) ([]byte, error)

Form_PUT 表单put

func (*WebClient) Form_request

func (me *WebClient) Form_request(method Method, relativePath string, params Form,
	handles ...responseHandle) ([]byte, error)

Form_request 表单请求

func (*WebClient) GetCookies

func (me *WebClient) GetCookies(rawURL string) ([]*http.Cookie, error)

GetCookies 根据域名获取cookies

func (*WebClient) HTTP_request

func (me *WebClient) HTTP_request(method Method, relativePath string,
	contentType string, params io.Reader,
	header map[string]interface{}) (*http.Response, error)

HTTP_request http请求

func (*WebClient) JSON_DELETE

func (me *WebClient) JSON_DELETE(relativePath string,
	params interface{}, response interface{},
	handles ...responseHandle) error

JSON_DELETE JSON delete

func (*WebClient) JSON_GET

func (me *WebClient) JSON_GET(relativePath string,
	params interface{}, response interface{},
	handles ...responseHandle) error

JSON_GET JSON get

func (*WebClient) JSON_POST

func (me *WebClient) JSON_POST(relativePath string,
	params interface{}, response interface{},
	handles ...responseHandle) error

JSON_POST JSON post

func (*WebClient) JSON_PUT

func (me *WebClient) JSON_PUT(relativePath string,
	params interface{}, response interface{},
	handles ...responseHandle) error

JSON_PUT JSON put

func (*WebClient) JSON_request

func (me *WebClient) JSON_request(method Method, relativePath string,
	params interface{}, response interface{},
	handles ...responseHandle) error

JSON_request JSON请求

func (*WebClient) SetCookie

func (me *WebClient) SetCookie(rawURL string, name string, value string) error

SetCookie 根据域名设置单条cookie

func (*WebClient) SetCookies

func (me *WebClient) SetCookies(rawURL string, cookies []*http.Cookie) error

SetCookies 根据域名设置cookies

func (*WebClient) SetHeader

func (me *WebClient) SetHeader(key string, value string)

Set_Token 设置token

func (*WebClient) UploadFile

func (me *WebClient) UploadFile(relativePath string, field string,
	path string, params Form,
	handles ...responseHandle) ([]byte, error)

UploadFile 文件上传方法

type WebServer

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

WebServer web服务辅助工具

func NewWebServerDefault

func NewWebServerDefault(listen string) *WebServer

NewWebServerDefault 构建web服务数据对象,domain可以为空

func (*WebServer) HandleDELETE

func (me *WebServer) HandleDELETE(relativePath string, handle func(Context)) *WebServer

HandleDELETE 监听Delete

func (*WebServer) HandleFunc

func (me *WebServer) HandleFunc(method Method, relativePath string, handle func(Context)) *WebServer

Handle_Func 监听函数

func (*WebServer) HandleGET

func (me *WebServer) HandleGET(relativePath string, handle func(Context)) *WebServer

HandleGET 监听Get

func (*WebServer) HandleOPTIONS

func (me *WebServer) HandleOPTIONS(relativePath string, handle func(Context)) *WebServer

HandleOPTIONS 监听Options

func (*WebServer) HandlePATCH

func (me *WebServer) HandlePATCH(relativePath string, handle func(Context)) *WebServer

HandlePATCH 监听Patch

func (*WebServer) HandlePOST

func (me *WebServer) HandlePOST(relativePath string, handle func(Context)) *WebServer

HandlePOST 监听Post

func (*WebServer) HandlePUT

func (me *WebServer) HandlePUT(relativePath string, handle func(Context)) *WebServer

HandlePUT 监听Put

func (*WebServer) HandleStruct

func (me *WebServer) HandleStruct(relativePath string, handle interface{}) *WebServer

HandleStruct 监听结构体,反射街头的http方法以及遍历每个字段的http方法,实现REST形式的API服务 结构体的方法必须与 Method 类型的名称一致

func (*WebServer) Run

func (me *WebServer) Run() error

Run 运行web服务

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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