ghost

package module
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2019 License: Apache-2.0 Imports: 24 Imported by: 9

README

ghost - 为gin套上工程化DDD的外衣-。-

使个人或团队能够更简单、快速地搭建起一个工程化的DDD架构的web服务

设计目标
在领域驱动设计的指导下按照六边形架构,
实现统一的服务调用、可扩展的适配器插槽、清晰规范的领域方法论
依赖
  • go ^1.13
  • go mod
安装
go get -u github.com/limoxi/ghost
使用

设计理念&使用规范

TODO
  • 六边形架构,支持多种服务调用, restApi, gRPC, websocket ...
  • resource api设计
  • 中间件设计
  • orm
  • 数据库事务应用策略
  • 配置文件设计
  • 支持配置中心修改配置
  • 异常处理
  • 分布式锁
  • 日志
  • docker部署
  • 代码规范

升级日志

项目参考

《实现领域驱动设计》[美] Vaughn Vernon 著;滕云 译 gin gorm logrus

Documentation

Index

Constants

View Source
const SERVICE_BUSINESS_ERROR_CODE = 520 // 业务错误
View Source
const SERVICE_INNER_SUCCESS_CODE = 200
View Source
const SERVICE_SUCCESS_CODE = 200 // 业务成功
View Source
const SERVICE_SYSTEM_ERROR_CODE = 530 // 系统错误
View Source
const VERSION = "0.0.3"

Variables

View Source
var (
	Debug  = log.Debugln
	Debugf = log.Debugf
	Info   = log.Infoln
	Infof  = log.Infof
	Warn   = log.Warningln
	Warnf  = log.Warningf
	Error  = log.Errorln
	Errorf = log.Errorf
	Panic  = log.Panicln
	Panicf = log.Panicf
)
View Source
var Config *config

Functions

func CloseAllDBConnections

func CloseAllDBConnections()

func ConnectDB

func ConnectDB(dbconfig *dbConfig, args ...string) *gorm.DB

func GetDB

func GetDB(args ...string) *gorm.DB

func NewDbConfig

func NewDbConfig(engine, host, port, user, pwd, dbname string, args ...int) *dbConfig

func NewDbConfigFromDSN

func NewDbConfigFromDSN(engine, dsn string) *dbConfig

func RegisterApi

func RegisterApi(r apiInterface)

func RegisterDBModel

func RegisterDBModel(dm dbModel, args ...string)

func RegisterGroupedApi

func RegisterGroupedApi(groupName string, r apiInterface)

func RegisterMiddleware

func RegisterMiddleware(m middlewareInterFace)

func RunWebServer

func RunWebServer()

func SyncDB

func SyncDB(args ...string)

SyncDB 将定义的model同步到数据库

Types

type ApiTemplate

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

func (*ApiTemplate) Bind

func (a *ApiTemplate) Bind(obj interface{})

绑定参数到struct

func (*ApiTemplate) Delete

func (a *ApiTemplate) Delete() Response

func (*ApiTemplate) Get

func (a *ApiTemplate) Get() Response

func (*ApiTemplate) GetCtx

func (a *ApiTemplate) GetCtx() *gin.Context

func (*ApiTemplate) GetLock

func (a *ApiTemplate) GetLock() string

func (*ApiTemplate) GetResource

func (a *ApiTemplate) GetResource() string

func (*ApiTemplate) Head

func (a *ApiTemplate) Head() Response

func (*ApiTemplate) Options

func (a *ApiTemplate) Options() Response

func (*ApiTemplate) Post

func (a *ApiTemplate) Post() Response

func (*ApiTemplate) Put

func (a *ApiTemplate) Put() Response

type BaseError

type BaseError struct {
	ErrCode string
	ErrMsg  string
	// contains filtered or unexported fields
}

func DefaultError

func DefaultError(errMsg string) *BaseError

func NewBusinessError

func NewBusinessError(args ...string) *BaseError

func NewSystemError

func NewSystemError(args ...string) *BaseError

func (*BaseError) GetCode

func (this *BaseError) GetCode() int

func (*BaseError) GetData

func (this *BaseError) GetData() interface{}

func (*BaseError) IsBusinessError

func (this *BaseError) IsBusinessError() bool

func (*BaseError) IsSystemError

func (this *BaseError) IsSystemError() bool

type BaseModel

type BaseModel struct {
	Id        int `gorm:"primary_key"`
	CreatedAt time.Time
}

type ContextObject

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

func (*ContextObject) GetCtx

func (c *ContextObject) GetCtx() context.Context

func (*ContextObject) SetCtx

func (c *ContextObject) SetCtx(ctx context.Context)

type DomainModel

type DomainModel struct {
	DomainObject
}

DomainModel 领域模型(表示实体)

func (*DomainModel) GetDbModel

func (this *DomainModel) GetDbModel() interface{}

func (*DomainModel) NewFromDbModel

func (this *DomainModel) NewFromDbModel(do interface{}, dbModel interface{})

NewFromDbModel 使用反射机制将dbModel中的field值复制到domainObject中

type DomainObject

type DomainObject struct {
	ContextObject
}

DomainObject 领域对象(可以表示聚合根、聚合、实体、值对象和领域服务)

type GMap

type GMap map[string]interface{}

func NewEmptyGMap

func NewEmptyGMap() GMap

func NewGMapFromData

func NewGMapFromData(data map[string]interface{}) GMap

func (GMap) Get

func (m GMap) Get(key string) interface{}

func (GMap) GetBool

func (m GMap) GetBool(key string, args ...bool) bool

func (GMap) GetFloat

func (m GMap) GetFloat(key string, args ...float64) float64

func (GMap) GetInt

func (m GMap) GetInt(key string, args ...int) int

func (GMap) GetString

func (m GMap) GetString(key string, args ...string) string

type JsonResponse

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

func NewErrorJsonResponse

func NewErrorJsonResponse(errCode string, args ...string) *JsonResponse

func NewJsonResponse

func NewJsonResponse(data interface{}) *JsonResponse

func (*JsonResponse) GetCode

func (this *JsonResponse) GetCode() int

func (*JsonResponse) GetData

func (this *JsonResponse) GetData() interface{}

func (*JsonResponse) GetDataType

func (this *JsonResponse) GetDataType() string

type Map

type Map = map[string]interface{}

type RawResponse

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

func NewErrorRawResponse

func NewErrorRawResponse(msg string) *RawResponse

func NewRawResponse

func NewRawResponse(msg string) *RawResponse

func (*RawResponse) GetCode

func (this *RawResponse) GetCode() int

func (*RawResponse) GetData

func (this *RawResponse) GetData() interface{}

func (*RawResponse) GetDataType

func (this *RawResponse) GetDataType() string

type RequestParams

type RequestParams struct {
	GMap
}

func (RequestParams) GetFile

func (rp RequestParams) GetFile(key string) *multipart.FileHeader

func (RequestParams) GetFiles

func (rp RequestParams) GetFiles(key string) []*multipart.FileHeader

type Response

type Response interface {
	GetCode() int
	GetData() interface{}
	GetDataType() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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