common

package module
v0.0.0-...-f111513 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: MIT Imports: 19 Imported by: 23

README

gin_common

gin common for the project which using the gin framework, like go_gin_sample

说明

使用 gin_common 来快速构建基于 gin 框架的程序。

也可以使用现有的例子 : go_gin_sample

https://github.com/tsbxmw/go_gin_sample

内容

封装了一揽子常用的功能。

common :

  • app 构建 :基于 github.com/urfave/cli
  • config :基于 github.com/spf13/viper
  • orm :基于 github.com/jinzhu/gorm
  • redis :基于 github.com/garyburd/redigo/redis
  • opentracing : 基于 github.com/opentracing/opentracing-go
  • rabbitmq : 基于 github.com/streadway/amqp
  • logrus :基于 github.com/sirupsen/logrus
  • consul : 基于 github.com/hashicorp/consul

middleware :

  • apidoc :基于 github.com/betacraft/yaag
  • exception : 修改于 go-gin 的 recovery
  • logger-file : 基于 github.com/lestrrat/go-file-rotatelogs
  • response : common response
  • jaeger : github.com/uber/jaeger-client-go/

重写 handler 方法

  • NoRouter
  • NoMethod

Documentation

Index

Constants

View Source
const (
	HTTP_MISS_PARAMS  = 101
	HTTP_PARAMS_ERROR = 102

	HTTP_STATUS_OK = 200

	HTTP_AUTH_ERROR     = 403
	HTTP_INTERNAL_ERROR = 503

	REDIS_SET_ERROR = 1001
	REDIS_GET_ERROR = 1002

	MYSQL_QUERY_ERROR  = 2001
	MYSQL_CREATE_ERROR = 2002
	MYSQL_UPDATE_ERROR = 2003

	HTTP_RESPONSE_OK = 0
)
View Source
const (
	HTTP_AUTH_ERROR_MSG    = "Auth Error"
	HTTP_MESSAGE_OK        = "success"
	MYSQL_CREATE_ERROR_MSG = "Mysql Create Error"
)

Variables

View Source
var DB *gorm.DB
View Source
var LogrusLogger *logrus.Logger
View Source
var (
	RedisPool *redis.Pool
)

Functions

func App

func App(serviceName string, serviceUsage string, httpServer HttpServer, serviceConfig ServiceConfig) (app *cli.App,
	err error)

func CloseDB

func CloseDB()

func GetDBIndex

func GetDBIndex(taskId int) (index string)

func InitDB

func InitDB(DbUri string)

func InitKey

func InitKey(c *gin.Context)

func InitLogger

func InitLogger() *logrus.Logger

func InitRedisPool

func InitRedisPool(network string, host string, password string, database int) (pool *redis.Pool)

func LocalIP

func LocalIP() string

func NewHttpAuthError

func NewHttpAuthError() error

func NewMySqlCreateError

func NewMySqlCreateError() error

func RedisGet

func RedisGet(ctx *gin.Context, redisConn redis.Conn, key string) (value string, err error)

func RedisGetCommon

func RedisGetCommon(redisConn redis.Conn, key string) (value string, err error)

func RedisSet

func RedisSet(ctx *gin.Context, redisConn redis.Conn, key string, value interface{}) (code int, err error)

func RedisSetCommon

func RedisSetCommon(redisConn redis.Conn, key string, value interface{}) (code int, err error)

Types

type AuthGlobal

type AuthGlobal struct {
	UserId int `json:"user_id"`
}

type AuthModel

type AuthModel struct {
	BaseModel
	UserId    int    `json:"user_id"`
	AppKey    string `json:"app_key"`
	AppSecret string `json:"app_secret"`
	Status    int    `json:"status";gorm:"DEFAULT:0"`
}

func (AuthModel) TableName

func (AuthModel) TableName() string

type AuthRedis

type AuthRedis struct {
	UserId int    `json:"user_id"`
	Secret string `json:"secret"`
	Key    string `json:"key"`
}

type BaseModel

type BaseModel struct {
	ID           int       `gorm:"primary_key" json:"id"`
	CreationTime time.Time `json:"creation_time"`
	ModifiedTime time.Time `json:"modified_time"`
}

type BaseModelCreate

type BaseModelCreate struct {
	ID           int       `gorm:"primary_key" json:"id"`
	CreationTime time.Time `json:"creation_time"`
}

type BaseModelName

type BaseModelName struct {
	ID   int    `gorm:"primary_key" json:"id"`
	Name string `json:"name"`
}

type BaseModelNormal

type BaseModelNormal struct {
	ID int `gorm:"primary_key" json:"id"`
}

type BaseService

type BaseService struct {
	Ctx *gin.Context
}

type GinResponse

type GinResponse struct {
	Ctx *gin.Context
}

func (*GinResponse) Response

func (gr *GinResponse) Response(code int, msg string, data interface{})

type HttpAuthError

type HttpAuthError struct {
	Code    int
	Message string
}

func (HttpAuthError) Error

func (hae HttpAuthError) Error() string

type HttpServer

type HttpServer interface {
	Serve(mode string)
	ServeWorker(mode string)
	Shutdown()
	Init(config ServiceConfig, configPath string) HttpServer
}

type HttpServerImpl

type HttpServerImpl struct {
	DB            *gorm.DB
	SvcName       string
	Address       string
	Port          int
	GrpcPort      string
	DbUri         string
	ConsulAddr    string
	ConsulPort    int
	JaegerAddr    string
	RedisHost     string
	RedisPort     string
	RedisPassword string
	RedisDB       int
	MqUri         string
}

type MysqlCreateError

type MysqlCreateError struct {
	Code    int
	Message string
}

func (MysqlCreateError) Error

func (mce MysqlCreateError) Error() string

type PageBaseRequest

type PageBaseRequest struct {
	PageSize  int `json:"page_size"`
	PageIndex int `json:"page_index"`
}

type PageFormBaseRequest

type PageFormBaseRequest struct {
	PageSize  int `form:"page_size"`
	PageIndex int `form:"page_index"`
}

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"msg"`
	Data    interface{} `json:"data"`
}

type ServiceConfig

type ServiceConfig interface {
	ConfigFromFileName(config string) ServiceConfig
}

type ServiceConfigImpl

type ServiceConfigImpl struct {
	ServiceName   string
	LogFile       string
	JaegerAddr    string
	ConsulAddr    string
	ConsulPort    int
	HttpAddr      string
	DbUri         string
	Port          int
	RedisHost     string
	RedisPort     string
	RedisPassword string
	RedisDB       int
	MqUri         string
}

func (ServiceConfigImpl) ConfigFromFileName

func (serviceConfig ServiceConfigImpl) ConfigFromFileName(config string) ServiceConfig

Directories

Path Synopsis
mq

Jump to

Keyboard shortcuts

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