ginkit

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 39 Imported by: 2

README

Ginkit Golang Gin Web Framework

Build Status Go Report Card GoDoc Release

We love Gin! Ginkit is written in Go and extends the Gin Web Framework with essential features and enhancements to make your life better! If you love Gin, you will love Ginkit.

The key features of Ginkit are:

  • easy
  • saml auth
  • token auth
  • template and layout built in
  • reverse proxy built in
  • simple data wrappers
  • auto handling of response data
  • oauto support built in

Getting started

Prerequisites
Getting Ginkit

With Go module support, simply add the following import

import "github.com/gokitcloud/ginkit"

to your code, and then go [build|run|test] will automatically fetch the necessary dependencies.

Otherwise, run the following Go command to install the ginkit package:

$ go get -u github.com/gokitcloud/ginkit
Running Ginkit

First you need to import Ginkit package for using Gin, and set up the simple example below:
from simple

package main

import (
	"github.com/gokitcloud/ginkit"
)

func main() {
	r := ginkit.Default()
	r.GET("/ping", ginkit.H{
		"message": "pong",
	})
	r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

And use the Go command to run the demo:

# run simple.go from the examples/simple directory
# and visit 0.0.0.0:8080/ping on browser
$ go run simple.go
Learn more examples
Quick Start

Learn and practice more examples, please read the Ginkit Quick Start which includes API examples and builds tag.

Examples

A number of ready-to-run examples demonstrating various use cases of Ginkit in the examples folder.

Documentation

See API documentation and descriptions for package documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRequestHeader

func AddRequestHeader(header, key string) func(*gin.Context)

func BasicAuthMiddleware

func BasicAuthMiddleware(accounts gin.Accounts) func(c *gin.Context)

func CertTemplate

func CertTemplate() (*x509.Certificate, error)

func CreateCert

func CreateCert(template, parent *x509.Certificate, pub interface{}, parentPriv interface{}) (
	cert *x509.Certificate, certPEM []byte, err error)

func GenerateCertificates

func GenerateCertificates() ([]tls.Certificate, error)

func GinRunSelfSignedSSL

func GinRunSelfSignedSSL(r *gin.Engine, addr string) (err error)

func JWTAuthCachedMiddleware added in v0.5.0

func JWTAuthCachedMiddleware(jwksURL, boundIssuer, jwtheader, claimid string) func(c *gin.Context)

func JWTAuthMiddleware added in v0.5.0

func JWTAuthMiddleware(jwksURL, boundIssuer, jwtheader, claimid string) func(c *gin.Context)

func LogoutRoute

func LogoutRoute(c *gin.Context)

func MetricsMiddleware

func MetricsMiddleware(metric string, keys ...any) func(c *gin.Context)

func Proxy

func Proxy(target string) func(*gin.Context)

func RBACMiddleware

func RBACMiddleware(config *RBACConfig) func(c *gin.Context)

func RBACTokenParamMiddleware

func RBACTokenParamMiddleware(model, policy any, tokenHeader string, params []string) func(c *gin.Context)

func RBACTokenPathMiddleware

func RBACTokenPathMiddleware(model, policy any, tokenHeader string) func(c *gin.Context)

func RemoveHeaders

func RemoveHeaders(headers ...string) func(*gin.Context)

func RequireAuthMiddleware added in v0.5.0

func RequireAuthMiddleware() func(c *gin.Context)

func ReturnData

func ReturnData(c *gin.Context, status int, data any)

func SAMLMiddleware

func SAMLMiddleware(samlSP *samlsp.Middleware) func(c *gin.Context)

func SAMLtoParamsMapMiddleware

func SAMLtoParamsMapMiddleware(params map[string]string) func(c *gin.Context)

func SAMLtoParamsMiddleware

func SAMLtoParamsMiddleware(params ...string) func(c *gin.Context)

func SimpleTokenAuthMiddleware

func SimpleTokenAuthMiddleware(token, header string) func(c *gin.Context)

func SimpleTokenAuthOptionalMiddleware

func SimpleTokenAuthOptionalMiddleware(token, header string) func(c *gin.Context)

func WrapBytes

func WrapBytes(b []byte) func(*gin.Context)

func WrapDataFunc

func WrapDataFunc(f func() (any, error)) func(*gin.Context)

func WrapDataFuncContext

func WrapDataFuncContext(f func(*gin.Context) (any, error)) func(*gin.Context)

func WrapDataFuncParams

func WrapDataFuncParams(f func(Params) (any, error)) func(*gin.Context)

func WrapErrorFunc

func WrapErrorFunc(f func() error) func(*gin.Context)

func WrapGinH

func WrapGinH(d gin.H) func(*gin.Context)

func WrapH

func WrapH(d H) func(*gin.Context)

func WrapString

func WrapString(s string) func(*gin.Context)

Types

type Engine

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

func Default

func Default() (r *Engine)

func New

func New() *Engine

func NewDefault

func NewDefault() (r *Engine)

func NewDefaultWithSessions

func NewDefaultWithSessions(sessionType, name, secret string) (r *Engine)

func (*Engine) AddHealthCheckFunc

func (e *Engine) AddHealthCheckFunc(f func() error) *Engine

func (*Engine) AddTemplateFunc

func (e *Engine) AddTemplateFunc(k string, v interface{}) *Engine

func (*Engine) Any

func (e *Engine) Any(relativePath string, f ...any)

func (*Engine) DELETE

func (e *Engine) DELETE(relativePath string, f ...any)

func (*Engine) GET

func (e *Engine) GET(relativePath string, f ...any)

func (*Engine) HEAD

func (e *Engine) HEAD(relativePath string, f ...any)

func (*Engine) HTML

func (e *Engine) HTML(template string, f any) func(*gin.Context)

func (*Engine) HTMLWithError

func (e *Engine) HTMLWithError(template, errorTemplate string, f any) func(*gin.Context)

func (*Engine) Handle

func (e *Engine) Handle(httpMethod, relativePath string, funcs ...any)

func (*Engine) HealthCheckRoute

func (e *Engine) HealthCheckRoute(c *gin.Context)

func (*Engine) JWTAuthGroup added in v0.5.0

func (e *Engine) JWTAuthGroup(path, jwksURL, boundIssuer, jwtheader, claimid string) *RouterGroup

func (*Engine) NoRoute

func (e *Engine) NoRoute(funcs ...any)

func (*Engine) NoRouteHTML

func (e *Engine) NoRouteHTML(template string, f any)

func (*Engine) NoRouteProxy

func (e *Engine) NoRouteProxy(target string)

func (*Engine) NoRouteRedirect

func (e *Engine) NoRouteRedirect(location string)

func (*Engine) OAuthGroup

func (e *Engine) OAuthGroup(path string, authServerURL string, config oauth2.Config) *gin.RouterGroup

func (*Engine) OAuthMW added in v0.10.0

func (e *Engine) OAuthMW(path string, authServerURL string, config oauth2.Config) gin.HandlerFunc

func (*Engine) OPTIONS

func (e *Engine) OPTIONS(relativePath string, f ...any)

func (*Engine) PATCH

func (e *Engine) PATCH(relativePath string, f ...any)

func (*Engine) POST

func (e *Engine) POST(relativePath string, f ...any)

func (*Engine) PUT

func (e *Engine) PUT(relativePath string, f ...any)

func (*Engine) RBACGroup

func (e *Engine) RBACGroup(path string, config *RBACConfig) *gin.RouterGroup

func (*Engine) RBACTokenParamGroup

func (e *Engine) RBACTokenParamGroup(path string, model, policy any, tokenHeader string, params []string) *gin.RouterGroup

func (*Engine) RBACTokenPathGroup

func (e *Engine) RBACTokenPathGroup(path string, model, policy any, tokenHeader string) *gin.RouterGroup

func (*Engine) Redirect

func (e *Engine) Redirect(location string) gin.HandlerFunc

func (*Engine) Router

func (e *Engine) Router() *gin.Engine

func (*Engine) Run

func (e *Engine) Run(addr ...string) error

func (*Engine) RunSSLSelfSigned

func (e *Engine) RunSSLSelfSigned(addr string) error

func (*Engine) SAMLGroup

func (e *Engine) SAMLGroup(path string, config *SAMLGroupConfig) *gin.RouterGroup

func (*Engine) SAMLInit

func (e *Engine) SAMLInit(config *SAMLGroupConfig) *samlsp.Middleware

func (*Engine) SAMLSetup added in v0.8.0

func (e *Engine) SAMLSetup(config *SAMLGroupConfig) *samlsp.Middleware

func (*Engine) SetVersion

func (e *Engine) SetVersion(version string) *Engine

func (*Engine) SimpleTokenAuthGroup

func (e *Engine) SimpleTokenAuthGroup(path, token, header string) *RouterGroup

func (*Engine) Static

func (e *Engine) Static(assets string) *Engine

func (*Engine) Templates

func (e *Engine) Templates(views string, partials []string) *Engine

type H

type H map[string]any

type Param

type Param struct {
	Key   string
	Value string
}

type Params

type Params []Param

func NewParams

func NewParams(p gin.Params) Params

func (Params) Get

func (ps Params) Get(name string) (string, bool)

type RBACConfig

type RBACConfig struct {
	Model  any
	Policy any
	Params []any
}

TODO: Implement RBACConfig

type RouterGroup

type RouterGroup struct {
	gin.RouterGroup
}

func (*RouterGroup) Any

func (r *RouterGroup) Any(relativePath string, funcs ...any)

func (*RouterGroup) DELETE

func (r *RouterGroup) DELETE(relativePath string, funcs ...any)

func (*RouterGroup) GET

func (r *RouterGroup) GET(relativePath string, funcs ...any)

func (*RouterGroup) HEAD

func (r *RouterGroup) HEAD(relativePath string, funcs ...any)

func (*RouterGroup) Handle

func (r *RouterGroup) Handle(httpMethod, relativePath string, funcs ...any)

func (*RouterGroup) OPTIONS

func (r *RouterGroup) OPTIONS(relativePath string, funcs ...any)

func (*RouterGroup) PATCH

func (r *RouterGroup) PATCH(relativePath string, funcs ...any)

func (*RouterGroup) POST

func (r *RouterGroup) POST(relativePath string, funcs ...any)

func (*RouterGroup) PUT

func (r *RouterGroup) PUT(relativePath string, funcs ...any)

type SAMLGroupConfig

type SAMLGroupConfig struct {
	MetaDataFile string
	MetaDataURL  string
	CertFile     string
	KeyFile      string
	EntityID     string
	RootURL      string
	ParamMap     map[string]string
	AllowSkip    bool
}

metadataFile metadata.xml certFile myservice.cert keyFile myservice.key entityID asdfasdf rootURL https://devlocal.site:8000 ACS URL: /saml/acs TODO: Implement SAMLGroupConfig

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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