core

package
v0.0.5-beta Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const ENV_MODE_KEY = "JSON_ENV_MODE"

Variables

This section is empty.

Functions

func CreateConfig

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

func CreateDir

func CreateDir(path string) error

func CreateFile

func CreateFile(path string) (*os.File, error)

func CreateFunc

func CreateFunc(file *ast.File, name string, params *ast.FieldList, content *ast.BlockStmt)

func CreateFunction

func CreateFunction(file *ast.File, name string, content *ast.BlockStmt)

func DefaultErrorHandler

func DefaultErrorHandler(err error) error

func Exists

func Exists(path string) (isDir bool, exists bool, err error)

func FindPIDByPort

func FindPIDByPort(port string) (string, 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 GetModuleFullPath

func GetModuleFullPath(module string) (string, error)

func GetModuleName

func GetModuleName() (string, error)

func GetModulePath

func GetModulePath() (string, error)

func KillProcess

func KillProcess(pid string) error

func NewApp

func NewApp() *fiber.App

func OnlyCreateFile

func OnlyCreateFile(path string) error

func ParseFile

func ParseFile(filePath string) (node *ast.File, fset *token.FileSet, err error)

parseFile 解析 Go 文件为 AST

func Raise

func Raise[T any](res T, err error) T

func RaiseVoid

func RaiseVoid(err error)

func SetMode

func SetMode(mode ENV_MODE)

func StartApp

func StartApp(app *fiber.App)

func Throw

func Throw(err error)

func TryCatch

func TryCatch[T any](fn func() T, errHandler ErrorHandler) (res T, err error)

func TryCatchVoid

func TryCatchVoid(fn func(), errHandler ErrorHandler) error

func UpperCamelCase

func UpperCamelCase(s string) string

func WriteToFile

func WriteToFile(file *ast.File, filePath string) error

func WriteToFileByFset

func WriteToFileByFset(fset *token.FileSet, file *ast.File, filePath string) error

Types

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:"-"`
	CreatedBy string         `json:"createdBy"`
	UpdatedBy string         `json:"updatedBy"`
	DeletedBy string         `json:"deletedBy"`
}

type BaseEntityWithID

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

type BaseEntityWithUuid

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

func (*BaseEntityWithUuid) BeforeCreate

func (e *BaseEntityWithUuid) BeforeCreate() error

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 ErrorHandler

type ErrorHandler func(error) error

type MatchType

type MatchType int
const (
	ExactMatch MatchType = iota
	RegexMatch
	ContainsMatch
)

type Route

type Route struct {
	Method string
	Path   string
}

type SearchResult

type SearchResult struct {
	Name string
	Node ast.Node
}

func FindFunctions

func FindFunctions(file *ast.File, pattern string, matchType MatchType) ([]SearchResult, error)

FindFunctions 查找函数定义

func FindInterfaces

func FindInterfaces(filePath string, pattern string, matchType MatchType) ([]SearchResult, error)

FindInterfaces 查找接口定义

func FindStructs

func FindStructs(filePath string, pattern string, matchType MatchType) ([]SearchResult, error)

FindStructs 查找结构体定义

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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