Help us shape the future of Go! Take the 2026 Go Developer Survey

exc

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: Apache-2.0 Imports: 4 Imported by: 12

README

exc

一个Golang应用程序快速开发框架,有以下特性

  • 快速开发
  • 内置配置文件加载
    • Yaml
    • Toml
    • Json
    • XML
    • 很方便定制自己的配置文件加载器
  • 内置强大的数据验证
    • 内置强大的且非常多的数据验证器
    • 很方便的定制自己的数据验证器
  • 强大的扩展功能
  • 强大的配置功能
    • 徽标
    • 帮助信息
    • 命令行
    • 一切可配置点皆可配置
  • 线程安全
  • 内置依赖注入
  • 语义化
    • 方便使用
    • 多态行为,同一个调用在不同的场景下有不同的意义

快速开始

Pangu使用非常简单,只需要定义两部分代码启动方法和启动器以及依赖关系,对于依赖关系

  • 可以没有依赖,如果没有,就不需要处理依赖
  • 一般稍微大型一点的系统都会有复杂的依赖关系,而这正是盘古框架的强项
  • 对于没有依赖或者依赖非常少的项目,使用盘古反而会使代码变多,这个需要大家酌情考虑

启动方法代码如下

package main

import (
    `github.com/pangum/pangu`
    `github.com/pangum/pangum`
)

func main() {
    panic(pangu.New(
        pangu.Named(`ziyunix`),
        pangu.Banner(`Ziyunix Server`, pangu.BannerTypeAscii),
    ).Run(newBootstrap))
}

启动器的代码如下

package main

type bootstrap struct {
    application *pangu.Application
}

func newBootstrap(application *pangu.Application) pangu.Bootstrap {
    return &bootstrap{
        application: application,
    }
}

依赖关系建议像如下处理

package rest

import (
	`github.com/pangum/pangu`
)

type Server struct {}

func newServer(/* 如果有依赖,可以在这里增加依赖:api *Api */) *Server {
	return new(Server)
}

func init() {
	pangu.New().Musts(
		newServer,
		// 其它依赖
		// ...
	)
}

Pangu有非常多的配置项,请参看使用文档

文档

点击这里查看最新文档

使用示例

点击这里查看最新的代码示例

项目实践

交流

微信群

捐助

支持宝 微信

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCode

func NewCode(code int) *codeDefault

NewCode 创建带状态码的异常

func NewException

func NewException(code int, message string, fields ...gox.Field[any]) *exceptionDefault

NewException 创建异常

func NewField

func NewField(message string, field gox.Field[any]) *fieldDefault

NewField 创建带字段的异常

func NewFields

func NewFields(message string, fields ...gox.Field[any]) *fieldsDefault

NewFields 创建带多个字段列表的异常

func NewMessage

func NewMessage(message string) *messageDefault

NewMessage 创建带消息的异常

Types

type Code

type Code interface {
	error

	// Code 返回错误码
	Code() int
}

Code 带状态码的异常

type Exception

type Exception interface {
	Code
	MessageException
	Fields
}

Exception 异常,符合条件的错误统一处理

type Field

type Field interface {
	error
	MessageException

	// Field 返回错误实体
	// 在某些错误下,可能需要返回额外的信息给前端处理
	// 比如,认证错误,需要返回哪些字段有错误
	Field() gox.Field[any]
}

Field 带字段的异常

type Fields

type Fields interface {
	error
	MessageException

	// Fields 返回错误实体
	// 在某些错误下,可能需要返回额外的信息给前端处理
	// 比如,认证错误,需要返回哪些字段有错误
	Fields() gox.Fields[any]
}

Fields 带多个字段列表的异常

type MessageException

type MessageException interface {
	error

	// Message 返回错误消息
	Message() string
}

MessageException 带消息的异常

Jump to

Keyboard shortcuts

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