server

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

README

server

server包是用于更加方便的开发web项目而封装的包,开启配置的话,如下

// main.go 文件
import (
    "github.com/gin-gonic/gin"
    "github.com/isyscore/isc-gobase/server"
    "github.com/isyscore/isc-gobase/server/rsp"
)

func main() {
    server.Get("group1/data", GetData)
    server.Run()
}

base:
  server:
    # 是否启用,默认:true
    enable: true
    # 端口号
    port: 8080
    # web框架gin的配置
    gin:
      # 有三种模式:debug/release/test
      mode: debug
    exception:
      # 异常返回打印
      print:
        # 是否启用:true, false;默认 true
        enable: true
        # 一些异常httpStatus不打印;默认可不填
        except:
          - 408
          - 409
    # 版本号设置,默认值:unknown
    version: 1.0.0
  # 内部开放的 endpoint
  endpoint:
    # 健康检查处理,默认关闭,true/false
    health:
      enable: true
    # 配置的管理(查看和变更),默认关闭,true/false
    config:
      enable: true

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApiPrefix = "/api"
View Source
var Version string = defaultVersion

Functions

func All added in v1.0.0

func All(path string, handler gin.HandlerFunc) gin.IRoutes

func AllWith added in v1.0.0

func AllWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func Cors

func Cors() gin.HandlerFunc

Cors 配置允许跨域请求

func Delete added in v1.0.0

func Delete(path string, handler gin.HandlerFunc) gin.IRoutes

func DeleteWith added in v1.0.0

func DeleteWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func Engine

func Engine() gin.IRoutes

func Get added in v1.0.0

func Get(path string, handler gin.HandlerFunc) gin.IRoutes

func GetPost added in v1.0.0

func GetPost(path string, handler gin.HandlerFunc) gin.IRoutes

func GetPostWith added in v1.0.0

func GetPostWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func GetWith added in v1.0.0

func GetWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes
func Head(path string, handler gin.HandlerFunc) gin.IRoutes

func HeadWith added in v1.0.0

func HeadWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func InitServer

func InitServer()

func Options added in v1.0.0

func Options(path string, handler gin.HandlerFunc) gin.IRoutes

func OptionsWith added in v1.0.0

func OptionsWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func Post added in v1.0.0

func Post(path string, handler gin.HandlerFunc) gin.IRoutes

func PostWith added in v1.0.0

func PostWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func Put added in v1.0.0

func Put(path string, handler gin.HandlerFunc) gin.IRoutes

func PutWith added in v1.0.0

func PutWith(path string, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func RegisterConfigWatchEndpoint added in v0.3.0

func RegisterConfigWatchEndpoint(apiBase string) gin.IRoutes

func RegisterCustomHealthCheck added in v0.2.0

func RegisterCustomHealthCheck(apiBase string, status func() string, init func() string, destroy func() string) gin.IRoutes

func RegisterHealthCheckEndpoint added in v0.3.0

func RegisterHealthCheckEndpoint(apiBase string) gin.IRoutes

func RegisterPlugin

func RegisterPlugin(plugin gin.HandlerFunc) gin.IRoutes

func RegisterRoute

func RegisterRoute(path string, method HttpMethod, handler gin.HandlerFunc) gin.IRoutes

func RegisterRouteWithHeaders added in v1.0.0

func RegisterRouteWithHeaders(path string, method HttpMethod, header []string, versionName []string, handler gin.HandlerFunc) gin.IRoutes

func RegisterStatic

func RegisterStatic(relativePath string, rootPath string) gin.IRoutes

func RegisterStaticFile

func RegisterStaticFile(relativePath string, filePath string) gin.IRoutes

func RegisterWebSocketRoute added in v0.8.0

func RegisterWebSocketRoute(path string, svr *websocket.Server) gin.IRoutes

func Run added in v1.0.0

func Run()

func StartServer

func StartServer()

Types

type ApiPath added in v1.0.0

type ApiPath struct {
	Path     string
	Handler  gin.HandlerFunc
	Method   HttpMethod
	Versions ISCList[*ApiVersion]
}

func GetApiPath added in v1.0.0

func GetApiPath(path string, method HttpMethod) *ApiPath

func NewApiPath added in v1.0.0

func NewApiPath(path string, method HttpMethod) *ApiPath

func (*ApiPath) AddVersion added in v1.0.0

func (ap *ApiPath) AddVersion(header []string, version []string, handler gin.HandlerFunc)

type ApiVersion added in v1.0.0

type ApiVersion struct {
	Header  []string
	Version []string
	Handler gin.HandlerFunc
}

type HttpMethod

type HttpMethod int
const (
	HmAll HttpMethod = iota
	HmGet
	HmPost
	HmPut
	HmDelete
	HmOptions
	HmHead
	HmGetPost
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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