core

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const ENV_MODE_KEY = "JSON_ENV_MODE"

Variables

View Source
var (
	ImportPath = "/projects/{projectId}/import-openapi"
)
View Source
var (
	Validator *validator.Validate
)

Functions

func AggregateEntities

func AggregateEntities(root, dest string) error

func CopyEntities

func CopyEntities(path, destPath string) (entities []string)

func CreateConfig

func CreateConfig(optsArr ...ConfigOptions) (*viper.Viper, error)

func GenerateFileExistsHandler

func GenerateFileExistsHandler(output string, tmpl string, params map[string]string, override bool) error

func GenerateFromTemplate

func GenerateFromTemplate(templatePath string, outPath string, params map[string]string) error

func GenerateFromTemplateFile

func GenerateFromTemplateFile(templateContent, outPath string, params map[string]string) error

func GenerateUUID

func GenerateUUID() string

func GetLevelPriority

func GetLevelPriority(level zapcore.Level) zap.LevelEnablerFunc

GetLevelPriority 根据 zapcore.Level 获取 zap.LevelEnablerFunc

func MarshalForFiber

func MarshalForFiber(v any) ([]byte, error)

func NewApp

func NewApp() *fiber.App

func NewGormMysql

func NewGormMysql(cnf configs.MysqlConfig, opts ...gorm.Option) (*gorm.DB, error)

func NewI18n

func NewI18n(config ...configs.I18nConfig) fiber.Handler

func NewLogger

func NewLogger(config configs.LogConfig) (logger *zap.Logger)

func NewRedis

func NewRedis(cnf configs.RedisConfig) (*redis.Client, error)

func ReadEntities

func ReadEntities(path string) (entities []string, node *ast.File, err error)

func SetMode

func SetMode(mode ENV_MODE)

func StartApp

func StartApp(app *fiber.App)

func UnmarshalForFiber

func UnmarshalForFiber(data []byte, v any) error

func ValidatorSetup

func ValidatorSetup()

Types

type Apifox

type Apifox struct{}

func (*Apifox) Import

func (a *Apifox) Import(data []byte) error

type BaseEntity

type BaseEntity struct {
	CreatedAt time.Time      `json:"createdAt" gorm:"index"`                     // 创建时间
	UpdatedAt time.Time      `json:"updatedAt"  gorm:"index"`                    // 更新时间
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-,intern" swaggerignore:"true"` // 删除时间
	CreatedBy string         `json:"createdBy"`                                  // 创建人
	UpdatedBy string         `json:"updatedBy"`                                  // 更新人
	DeletedBy string         `json:"deletedBy,intern" swaggerignore:"true"`      // 删除人
}

@Description 核心基础实体

func (BaseEntity) MarshalEasyJSON

func (v BaseEntity) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (BaseEntity) MarshalJSON

func (v BaseEntity) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*BaseEntity) UnmarshalEasyJSON

func (v *BaseEntity) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*BaseEntity) UnmarshalJSON

func (v *BaseEntity) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type BaseEntityWithID

type BaseEntityWithID struct {
	ID uint `json:"id" gorm:"primarykey"` // 主键ID
	BaseEntity
}

@Description 核心基础实体,带 ID

func (BaseEntityWithID) MarshalEasyJSON

func (v BaseEntityWithID) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (BaseEntityWithID) MarshalJSON

func (v BaseEntityWithID) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*BaseEntityWithID) UnmarshalEasyJSON

func (v *BaseEntityWithID) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*BaseEntityWithID) UnmarshalJSON

func (v *BaseEntityWithID) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type BaseEntityWithUuid

type BaseEntityWithUuid struct {
	ID string `json:"id" gorm:"primarykey;type:char(20)"` // 主键ID
	BaseEntity
}

@Description 核心基础实体,带 UUID

func (*BaseEntityWithUuid) BeforeCreate

func (e *BaseEntityWithUuid) BeforeCreate(tx *gorm.DB) error

func (BaseEntityWithUuid) MarshalEasyJSON

func (v BaseEntityWithUuid) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (BaseEntityWithUuid) MarshalJSON

func (v BaseEntityWithUuid) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*BaseEntityWithUuid) UnmarshalEasyJSON

func (v *BaseEntityWithUuid) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*BaseEntityWithUuid) UnmarshalJSON

func (v *BaseEntityWithUuid) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Config

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

func NewConfig

func NewConfig(optsArr ...ConfigOptions) (*Config, error)

func (*Config) Bind

func (c *Config) Bind(instance any) (err error)

type ConfigInterface

type ConfigInterface interface {
	Bind(instance any) error
}

type ConfigOptions

type ConfigOptions struct {
	BasePath  string
	FileName  string
	FileType  string
	WatchAble bool
	OnChange  func(e fsnotify.Event)
}

func DefaultConfigOptions

func DefaultConfigOptions() ConfigOptions

type ENV_MODE

type ENV_MODE string
const (
	DevMode  ENV_MODE = "development"
	ProMode  ENV_MODE = "production"
	TestMode ENV_MODE = "test"
)

func Mode

func Mode() ENV_MODE

func ParseEnv

func ParseEnv(env string) ENV_MODE

type ImportDTO

type ImportDTO struct {
	Input   string        `json:"input"`
	Options ImportOptions `json:"options"`
}

type ImportOptions

type ImportOptions struct {
	TargetEndpointFolderId        string `json:"targetEndpointFolderId"`
	TargetSchemaFolderId          string `json:"targetSchemaFolderId"`
	EndpointOverwriteBehavior     string `json:"endpointOverwriteBehavior"`
	SchemaOverwriteBehavior       string `json:"schemaOverwriteBehavior"`
	UpdateFolderOfChangedEndpoint bool   `json:"updateFolderOfChangedEndpoint"`
	PrependBasePath               bool   `json:"prependBasePath"`
}

type Logger

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

func NewLoggerConfig

func NewLoggerConfig(config configs.LogConfig) *Logger

func (*Logger) CusTimeEncoder

func (f *Logger) CusTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

CustomTimeEncoder 自定义日志输出时间格式

func (*Logger) GetEncoder

func (f *Logger) GetEncoder() zapcore.Encoder

GetEncoder 获取 zapcore.Encoder

func (*Logger) GetEncoderCore

func (f *Logger) GetEncoderCore(l zapcore.Level, level zap.LevelEnablerFunc) zapcore.Core

GetEncoderCore 获取Encoder的 zapcore.Core

func (*Logger) GetWriteSyncer

func (f *Logger) GetWriteSyncer(level string) zapcore.WriteSyncer

GetWriteSyncer 获取 zapcore.WriteSyncer

func (*Logger) GetZapCores

func (f *Logger) GetZapCores() []zapcore.Core

GetZapCores 根据配置文件的Level获取 []zapcore.Core

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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