gintool

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 17 Imported by: 0

README

GinTool - Gin Web Framework Config Tool

Gin is a web framework written in Go (Golang) with good performance. GinTool target to make Gin config and start much easier.

Installation

To install GinTool package, you need to install Go and set your Go workspace first.

  1. The first need Go installed (version 1.11+ is required), then you can use the below Go command to install GinTool.
$ go get -u github.com/cytown/gintool
  1. Import it in your code:
import "github.com/cytown/gintool"
  1. Test the GinTool
$ go test
  1. Start the example
$ go run example/example.go

Quick start

package main

import (
	"fmt"

	"github.com/gin-gonic/gin"
	"github.com/cytown/gintool"
)

func main() {
	ge, err := gintool.NewGin("testdata/gin.conf")
	if err != nil {
		fmt.Println("error: ", err)
		return
	}
	ge.Engine.GET("/", func(c *gin.Context) {
		c.JSON(200, gin.H{"hello": "world"})
	})
	err = ge.Start()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SessionGet

func SessionGet(name string) interface{}

SessionGet return the value stored in Session

func SessionSet

func SessionSet(name string, val interface{})

SessionSet store the value to Session

func UseSession

func UseSession(config *Config) gin.HandlerFunc

UseSession is a middleware which generate the session in gorouting Please be sure that all middleware use session must called after this middleware GinEngine default will use this middleware

func WithSession

func WithSession(f func()) func()

WithSession will create the session key in current gorouting

Types

type Config

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

Config the configuration

func SessionConfig

func SessionConfig() *Config

SessionConfig return the saved *Config, it must be called after Use(UseSession(*Config))

func (*Config) Get

func (c *Config) Get(key ...string) (ret interface{})

Get return the saved other configuration with key/value mapping

type GinEngine

type GinEngine struct {
	// Engine is the exposed *gin.Engine
	Engine *gin.Engine
	// contains filtered or unexported fields
}

GinEngine is the configuration of gin.Engine

func NewGin

func NewGin(path string) (*GinEngine, error)

NewGin will create a new GinEngine with the config file. Example config files check the config and testdata directory.

func (*GinEngine) AddTemplates

func (ge *GinEngine) AddTemplates(name string, files ...string)

AddTemplates to add templates with the specified name

func (*GinEngine) HandleSession

func (ge *GinEngine) HandleSession(method string, path string, handlerFunc gin.HandlerFunc) gin.IRoutes

HandleSession will create a new session with key map to store the value for future use. For example, you can store the language define in session then use it in template or i18n. Warning: you should not use session in middleware because it will be called after the middleware

func (*GinEngine) ShutDown

func (ge *GinEngine) ShutDown() (err error)

ShutDown will shutdown the engine

func (*GinEngine) Start

func (ge *GinEngine) Start() (ret error)

Start just start the engine, tls will according to the configuration file

type Session

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

Session can be used in app started with WithSession or UseSession

func GetSession

func GetSession() *Session

GetSession get the Session, if not exist return new

func NewSession

func NewSession() *Session

NewSession create new Session

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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