gins

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ApiTitle     string          `mapstructure:"api_title"`   // for openapi
	ApiVersion   string          `mapstructure:"api_version"` // for openapi
	ApiServers   []OpenAPIServer `mapstructure:"api_servers"` // for openapi
	HttpPort     int             `mapstructure:"http_port"`
	GinMode      string          `mapstructure:"gin_mode"`
	Log          bool            `mapstructure:"log"`
	EnableCORS   bool            `mapstructure:"enable_cors"`
	APIRoot      string          `mapstructure:"api_root"`
	StaticRoutes []StaticRoute   `mapstructure:"static_routes"`
}

func (*Config) NewEngine

func (g *Config) NewEngine() (*gin.Engine, gin.IRouter)

func (*Config) NewOpenAPI

func (g *Config) NewOpenAPI() *openapi.Openapi

func (*Config) NewServer

func (c *Config) NewServer() *Server

func (*Config) TryServeFiles

func (g *Config) TryServeFiles(sr StaticRoute) gin.HandlerFunc

TryServeFiles attempts to serve static files from the specified directory. If the requested file does not exist, it serves a custom "not found" page.

type ConfigSection

type ConfigSection string
const DefaultConfigSection ConfigSection = "gin-service"

type Handler

type Handler struct {
	Request  Request
	Response Response
	Handler  func(c *gin.Context)
}

type OpenAPIServer

type OpenAPIServer struct {
	// on production, this should be the actual url, e.g. https://api.example.com/api/v1
	Url         string `mapstructure:"url"`
	Description string `mapstructure:"description"`
}

type Request

type Request struct {
	Description string
	Query       any // from url query
	Json        any // from body
	Form        any // from body
	Xml         any // from body
}

type Response

type Response struct {
	Description string
	Json        any
	Xml         any
}

type Route

type Route struct {
	Method      string
	Path        string
	Summary     string
	Description string
	Security    Security
	Handler     Handler
}

func (Route) Use

func (r Route) Use(h Security) Route

type Security

type Security interface {
	Auth(c *gin.Context)
	SecurityScheme() []map[string][]string
}

type Server

type Server struct {
	API       *openapi.Openapi
	Port      int
	Engine    *gin.Engine
	APIRouter gin.IRouter
}

func GetServer

func GetServer(c *ioc.Container) *Server

func GetServerByConfig

func GetServerByConfig(configSection ConfigSection, c *ioc.Container) *Server

func (*Server) Register

func (s *Server) Register(services ...*Service)

func (*Server) Run

func (s *Server) Run(ctx context.Context)

func (*Server) SetSecuritySchemes

func (s *Server) SetSecuritySchemes(schemes openapi.SecuritySchemes)

type Service

type Service struct {
	Tag         string
	Description string
	Path        string
	Routes      []Route
}

type StaticRoute

type StaticRoute struct {
	Route    string `mapstructure:"route"`
	Dir      string `mapstructure:"dir"`
	NotFound string `mapstructure:"not_found"`
}

Directories

Path Synopsis
docs

Jump to

Keyboard shortcuts

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