api

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 20 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIs = map[string]*API{}

APIs 已加载API列表

View Source
var HTTPGuards = map[string]gin.HandlerFunc{}

HTTPGuards 支持的中间件

Functions

func AddGuard

func AddGuard(name string, guard gin.HandlerFunc)

AddGuard add guard

func IsAllowed

func IsAllowed(c *gin.Context, allowsMap map[string]bool) bool

IsAllowed check if the referer is in allow list

func ProcessGuard

func ProcessGuard(name string) gin.HandlerFunc

ProcessGuard guard process

func SetGuards

func SetGuards(guards map[string]gin.HandlerFunc)

SetGuards set guards

func SetRoutes

func SetRoutes(router *gin.Engine, path string, allows ...string)

SetRoutes set the api routes

Types

type API

type API struct {
	ID   string `jsong:"id"`
	Name string
	File string
	Type string
	HTTP HTTP
}

API 数据接口

func Load

func Load(file, id string, guard ...string) (*API, error)

Load load the api

func Select

func Select(id string) *API

Select select api

func (*API) Reload

func (api *API) Reload() (*API, error)

Reload API

type HTTP

type HTTP struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description,omitempty"`
	Group       string `json:"group,omitempty"`
	Guard       string `json:"guard,omitempty"`
	Paths       []Path `json:"paths,omitempty"`
}

HTTP http 协议服务

func (HTTP) Route

func (http HTTP) Route(router gin.IRoutes, path Path, allows ...string)

Route 路径配置转换为路由

func (HTTP) Routes

func (http HTTP) Routes(router *gin.Engine, path string, allows ...string)

Routes 配置转换为路由

type Out

type Out struct {
	Status   int               `json:"status"`
	Type     string            `json:"type,omitempty"`
	Body     interface{}       `json:"body,omitempty"`
	Headers  map[string]string `json:"headers,omitempty"`
	Redirect *Redirect         `json:"redirect,omitempty"`
}

Out http 输出

type Path

type Path struct {
	Label       string        `json:"label,omitempty"`
	Description string        `json:"description,omitempty"`
	Path        string        `json:"path"`
	Method      string        `json:"method"`
	Process     string        `json:"process"`
	Guard       string        `json:"guard,omitempty"`
	In          []interface{} `json:"in,omitempty"`
	Out         Out           `json:"out,omitempty"`
}

Path HTTP Path

type Redirect

type Redirect struct {
	Code     int    `json:"code,omitempty"`
	Location string `json:"location,omitempty"`
}

Redirect out redirect

Jump to

Keyboard shortcuts

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