feat: 实现域名注册和管理功能
- 新增 ACME客户端功能,支持域名注册和证书申请 - 添加数据库模型和操作,用于存储和管理域名信息 - 实现 API 接口,提供域名注册、获取和分页查询功能 -集成全局错误处理和 panic捕获 - 添加单元测试和集成测试
This commit is contained in:
		
						commit
						b1adda8a55
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | .idea | ||||||
|  | acme-mane.db | ||||||
							
								
								
									
										39
									
								
								acme/acme.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								acme/acme.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,39 @@ | ||||||
|  | package acme | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"crypto/ecdsa" | ||||||
|  | 	"crypto/elliptic" | ||||||
|  | 	"crypto/rand" | ||||||
|  | 	"github.com/go-acme/lego/v4/certcrypto" | ||||||
|  | 	"github.com/go-acme/lego/v4/lego" | ||||||
|  | 	"github.com/go-acme/lego/v4/registration" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type DnsHelper interface { | ||||||
|  | 	Apply() | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func Register(email string) *RegisterRes { | ||||||
|  | 	privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	user := User{ | ||||||
|  | 		Email: email, | ||||||
|  | 		Key:   privateKey, | ||||||
|  | 	} | ||||||
|  | 	config := lego.NewConfig(&user) | ||||||
|  | 	config.CADirURL = lego.LEDirectoryProduction | ||||||
|  | 	config.Certificate.KeyType = certcrypto.RSA2048 | ||||||
|  | 	client, err := lego.NewClient(config) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	resource, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true}) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	user.Registration = resource | ||||||
|  | 	return user.ToRegister() | ||||||
|  | } | ||||||
							
								
								
									
										27
									
								
								acme/acme_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								acme/acme_test.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | ||||||
|  | package acme | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"testing" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func TestRegister(t *testing.T) { | ||||||
|  | 	register := Register("1302344380@qq.com") | ||||||
|  | 	fmt.Println(register.Email) | ||||||
|  | 	fmt.Println(register.PrivateKey) | ||||||
|  | 	fmt.Println(register.Registration) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestParseRegister(t *testing.T) { | ||||||
|  | 	res := RegisterRes{ | ||||||
|  | 		Email:        "1302344380@qq.com", | ||||||
|  | 		Registration: "{\"body\":{\"status\":\"valid\",\"contact\":[\"mailto:1302344380@qq.com\"]},\"uri\":\"https://acme-v02.api.letsencrypt.org/acme/acct/2379447617\"}", | ||||||
|  | 		PrivateKey:   "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgnxjIGpla+EGdl2+JcPBuE5T06wKYbp4x49aykmS84ryhRANCAARqMaBmXLfqgsJDmISHX9cLJcX19W51UjcKQ0rLllyf8YjOsxCZ+XHW/DpS/hh2VLgc5zpZtgBWOAskN1viAFKi", | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	user := User{} | ||||||
|  | 	register := user.FromRegister(&res) | ||||||
|  | 	fmt.Println(register.GetEmail()) | ||||||
|  | 	fmt.Println(register.GetPrivateKey()) | ||||||
|  | 	fmt.Println(register.GetRegistration()) | ||||||
|  | } | ||||||
							
								
								
									
										69
									
								
								acme/cloudflare.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								acme/cloudflare.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,69 @@ | ||||||
|  | package acme | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"crypto/ecdsa" | ||||||
|  | 	"crypto/elliptic" | ||||||
|  | 	"crypto/rand" | ||||||
|  | 	"fmt" | ||||||
|  | 	"github.com/go-acme/lego/v4/certcrypto" | ||||||
|  | 	"github.com/go-acme/lego/v4/certificate" | ||||||
|  | 	"github.com/go-acme/lego/v4/lego" | ||||||
|  | 	"github.com/go-acme/lego/v4/providers/dns/alidns" | ||||||
|  | 	"github.com/go-acme/lego/v4/registration" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func Apply() { | ||||||
|  | 
 | ||||||
|  | 	privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	user := User{ | ||||||
|  | 		Email: "123@qq.com", | ||||||
|  | 		Key:   privateKey, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	config := lego.NewConfig(&user) | ||||||
|  | 	config.CADirURL = lego.LEDirectoryProduction | ||||||
|  | 	config.Certificate.KeyType = certcrypto.RSA2048 | ||||||
|  | 	client, err := lego.NewClient(config) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	conf := alidns.NewDefaultConfig() | ||||||
|  | 	conf.APIKey = "123" | ||||||
|  | 	conf.SecretKey = "123" | ||||||
|  | 
 | ||||||
|  | 	provider, err := alidns.NewDNSProviderConfig(conf) | ||||||
|  | 	_ = client.Challenge.SetDNS01Provider(provider) | ||||||
|  | 
 | ||||||
|  | 	reg, _ := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true}) | ||||||
|  | 	user.Registration = reg | ||||||
|  | 
 | ||||||
|  | 	request := certificate.ObtainRequest{ | ||||||
|  | 		Domains: []string{"a.com", "b.com"}, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	resource, _ := client.Certificate.Obtain(request) | ||||||
|  | 	fmt.Println(resource) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func ReNew() { | ||||||
|  | 	privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	user := User{ | ||||||
|  | 		Email: "123@qq.com", | ||||||
|  | 		Key:   privateKey, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	config := lego.NewConfig(&user) | ||||||
|  | 	config.CADirURL = lego.LEDirectoryProduction | ||||||
|  | 	config.Certificate.KeyType = certcrypto.RSA2048 | ||||||
|  | 
 | ||||||
|  | 	resource := certificate.Resource{} | ||||||
|  | 	client, _ := lego.NewClient(config) | ||||||
|  | 	newResource, _ := client.Certificate.RenewWithOptions(resource, &certificate.RenewOptions{}) | ||||||
|  | 	fmt.Println(newResource) | ||||||
|  | } | ||||||
							
								
								
									
										73
									
								
								acme/resource_obj.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								acme/resource_obj.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,73 @@ | ||||||
|  | package acme | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"encoding/base64" | ||||||
|  | 	"encoding/json" | ||||||
|  | 	"github.com/go-acme/lego/v4/certificate" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type ResourceObj struct { | ||||||
|  | 	Domain            string `json:"domain"` | ||||||
|  | 	CertURL           string `json:"certUrl"` | ||||||
|  | 	CertStableURL     string `json:"certStableUrl"` | ||||||
|  | 	PrivateKey        string `json:"privateKey"` // 使用base64编码
 | ||||||
|  | 	Certificate       string `json:"certificate"` | ||||||
|  | 	IssuerCertificate string `json:"issuerCertificate"` | ||||||
|  | 	CSR               string `json:"csr"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func ResourceToJson(resource *certificate.Resource) []byte { | ||||||
|  | 	resourceObj := ResourceObj{ | ||||||
|  | 		Domain:            resource.Domain, | ||||||
|  | 		CertURL:           resource.CertURL, | ||||||
|  | 		CertStableURL:     resource.CertStableURL, | ||||||
|  | 		PrivateKey:        base64.StdEncoding.EncodeToString(resource.PrivateKey), | ||||||
|  | 		Certificate:       base64.StdEncoding.EncodeToString(resource.Certificate), | ||||||
|  | 		IssuerCertificate: base64.StdEncoding.EncodeToString(resource.IssuerCertificate), | ||||||
|  | 		CSR:               base64.StdEncoding.EncodeToString(resource.CSR), | ||||||
|  | 	} | ||||||
|  | 	resourceJson, err := json.Marshal(resourceObj) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	return resourceJson | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func ResourceFromJson(data []byte) certificate.Resource { | ||||||
|  | 	var resourceObj ResourceObj | ||||||
|  | 	err := json.Unmarshal(data, &resourceObj) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	privateKey, err := base64.StdEncoding.DecodeString(resourceObj.PrivateKey) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	cert, err := base64.StdEncoding.DecodeString(resourceObj.Certificate) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	issuerCertificate, err := base64.StdEncoding.DecodeString(resourceObj.IssuerCertificate) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	csr, err := base64.StdEncoding.DecodeString(resourceObj.CSR) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return certificate.Resource{ | ||||||
|  | 		Domain:            resourceObj.Domain, | ||||||
|  | 		CertURL:           resourceObj.CertURL, | ||||||
|  | 		CertStableURL:     resourceObj.CertStableURL, | ||||||
|  | 		PrivateKey:        privateKey, | ||||||
|  | 		Certificate:       cert, | ||||||
|  | 		IssuerCertificate: issuerCertificate, | ||||||
|  | 		CSR:               csr, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										76
									
								
								acme/user.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								acme/user.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,76 @@ | ||||||
|  | package acme | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"crypto" | ||||||
|  | 	"crypto/ecdsa" | ||||||
|  | 	"crypto/x509" | ||||||
|  | 	"encoding/base64" | ||||||
|  | 	"encoding/json" | ||||||
|  | 	"github.com/go-acme/lego/v4/registration" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type User struct { | ||||||
|  | 	Email        string | ||||||
|  | 	Registration *registration.Resource | ||||||
|  | 	Key          crypto.PrivateKey | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u *User) GetEmail() string { | ||||||
|  | 	return u.Email | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u *User) GetRegistration() *registration.Resource { | ||||||
|  | 	return u.Registration | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u *User) GetPrivateKey() crypto.PrivateKey { | ||||||
|  | 	return u.Key | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u *User) ToRegister() *RegisterRes { | ||||||
|  | 	registrationJson, err := json.Marshal(u.Registration) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	privateDER, err := x509.MarshalPKCS8PrivateKey(u.Key) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	privateBase64 := base64.StdEncoding.EncodeToString(privateDER) | ||||||
|  | 	return &RegisterRes{ | ||||||
|  | 		Email:        u.Email, | ||||||
|  | 		Registration: string(registrationJson), | ||||||
|  | 		PrivateKey:   privateBase64, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u *User) FromRegister(register *RegisterRes) *User { | ||||||
|  | 	u.Email = register.Email | ||||||
|  | 	err := json.Unmarshal([]byte(register.Registration), &u.Registration) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	privateDER, err := base64.StdEncoding.DecodeString(register.PrivateKey) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	key, err := x509.ParsePKCS8PrivateKey(privateDER) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	privateKey, e := key.(*ecdsa.PrivateKey) | ||||||
|  | 	if !e { | ||||||
|  | 		panic(e) | ||||||
|  | 	} | ||||||
|  | 	u.Key = privateKey | ||||||
|  | 	return u | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type RegisterRes struct { | ||||||
|  | 	Email        string | ||||||
|  | 	Registration string | ||||||
|  | 	PrivateKey   string | ||||||
|  | } | ||||||
							
								
								
									
										57
									
								
								config/config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								config/config.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,57 @@ | ||||||
|  | package config | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/util" | ||||||
|  | 	"fmt" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func init() { | ||||||
|  | 	initConfig() | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type Server struct { | ||||||
|  | 	Host string | ||||||
|  | 	Port string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type Db struct { | ||||||
|  | 	File string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type Admin struct { | ||||||
|  | 	username string | ||||||
|  | 	password string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type SysConfig struct { | ||||||
|  | 	Server Server | ||||||
|  | 	Db     Db | ||||||
|  | 	Admin  Admin | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | var conf *SysConfig | ||||||
|  | 
 | ||||||
|  | func GetConfig() *SysConfig { | ||||||
|  | 	return conf | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func initConfig() { | ||||||
|  | 	port := util.GetEnv("ACME_SERVER_PORT", "8080") | ||||||
|  | 	server := Server{ | ||||||
|  | 		Host: util.GetEnv("ACME_SERVER_HOST", "0.0.0.0"), | ||||||
|  | 		Port: port, | ||||||
|  | 	} | ||||||
|  | 	db := Db{ | ||||||
|  | 		File: util.GetEnv("ACME_DB_FILE", "acme-mane.db"), | ||||||
|  | 	} | ||||||
|  | 	admin := Admin{ | ||||||
|  | 		username: util.GetEnv("ACME_ADMIN_USERNAME", "acme-admin"), | ||||||
|  | 		password: util.GetEnv("ACME_ADMIN_PASSWORD", "acme-pass"), | ||||||
|  | 	} | ||||||
|  | 	conf = &SysConfig{ | ||||||
|  | 		Server: server, | ||||||
|  | 		Db:     db, | ||||||
|  | 		Admin:  admin, | ||||||
|  | 	} | ||||||
|  | 	fmt.Println(conf) | ||||||
|  | } | ||||||
							
								
								
									
										69
									
								
								dao/domain.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								dao/domain.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,69 @@ | ||||||
|  | package dao | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/db" | ||||||
|  | 	"acme-mana-server-go/model" | ||||||
|  | 	"acme-mana-server-go/vo" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type DomainDao struct { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (_ *DomainDao) Add(domain *model.Domain) *model.Domain { | ||||||
|  | 	conn := db.Db() | ||||||
|  | 	conn.Create(domain) | ||||||
|  | 	return domain | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (_ *DomainDao) Get(id int) *model.Domain { | ||||||
|  | 	res := &model.Domain{} | ||||||
|  | 	conn := db.Db() | ||||||
|  | 	tx := conn.First(res, id) | ||||||
|  | 	if tx.Error != nil { | ||||||
|  | 		panic(tx.Error) | ||||||
|  | 	} | ||||||
|  | 	return res | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (_ *DomainDao) List() []*model.Domain { | ||||||
|  | 	conn := db.Db() | ||||||
|  | 	res := make([]*model.Domain, 0) | ||||||
|  | 	conn.Find(&res) | ||||||
|  | 	return res | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (_ *DomainDao) Edit(newDomain *model.Domain) *model.Domain { | ||||||
|  | 	conn := db.Db() | ||||||
|  | 	conn.Save(newDomain) | ||||||
|  | 	return newDomain | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (_ *DomainDao) Delete(id int) { | ||||||
|  | 	conn := db.Db() | ||||||
|  | 	conn.Delete(&model.Domain{}, id) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (_ *DomainDao) Page(req *vo.DomainPageReq) (int64, *[]model.Domain) { | ||||||
|  | 	var total int64 | ||||||
|  | 	var list []model.Domain | ||||||
|  | 
 | ||||||
|  | 	conn := db.Db() | ||||||
|  | 	bean := req.Bean | ||||||
|  | 
 | ||||||
|  | 	query := conn.Model(&model.Domain{}) | ||||||
|  | 
 | ||||||
|  | 	if bean.Name != "" { | ||||||
|  | 		query = query.Where("name like ?", "%"+bean.Name+"%") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	query.Count(&total) | ||||||
|  | 	if total == 0 { | ||||||
|  | 		return total, &list | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	page := req.Page | ||||||
|  | 	query.Offset(page.Size * (page.Page - 1)).Limit(page.Size) | ||||||
|  | 
 | ||||||
|  | 	query.Find(&list) | ||||||
|  | 	return total, &list | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								dao/domain_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								dao/domain_test.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | ||||||
|  | package dao | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/model" | ||||||
|  | 	"fmt" | ||||||
|  | 	"testing" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func TestAdd(t *testing.T) { | ||||||
|  | 	domainDao := &DomainDao{} | ||||||
|  | 	domain := &model.Domain{ | ||||||
|  | 		Name:         "test", | ||||||
|  | 		Hosts:        "a.com", | ||||||
|  | 		ProviderConf: "", | ||||||
|  | 	} | ||||||
|  | 	domainDao.Add(domain) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestGet(t *testing.T) { | ||||||
|  | 	domainDao := &DomainDao{} | ||||||
|  | 	domain := domainDao.Get(2) | ||||||
|  | 	fmt.Println(domain) | ||||||
|  | } | ||||||
							
								
								
									
										33
									
								
								db/db.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								db/db.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | ||||||
|  | package db | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/config" | ||||||
|  | 	"acme-mana-server-go/model" | ||||||
|  | 	"github.com/glebarez/sqlite" | ||||||
|  | 	"gorm.io/gorm" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | var db *gorm.DB | ||||||
|  | 
 | ||||||
|  | func init() { | ||||||
|  | 	initDb() | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func Db() *gorm.DB { | ||||||
|  | 	return db | ||||||
|  | } | ||||||
|  | func initDb() { | ||||||
|  | 	conf := config.GetConfig() | ||||||
|  | 	dbConf := conf.Db | ||||||
|  | 	dbFile := dbConf.File | ||||||
|  | 	conn, err := gorm.Open(sqlite.Open(dbFile), &gorm.Config{}) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic("failed to connect database") | ||||||
|  | 	} | ||||||
|  | 	err = conn.AutoMigrate(&model.Domain{}) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	db = conn | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										9
									
								
								db/db_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								db/db_test.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | ||||||
|  | package db | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"testing" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func TestDb(t *testing.T) { | ||||||
|  | 	print(Db()) | ||||||
|  | } | ||||||
							
								
								
									
										59
									
								
								go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								go.mod
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,59 @@ | ||||||
|  | module acme-mana-server-go | ||||||
|  | 
 | ||||||
|  | go 1.24 | ||||||
|  | 
 | ||||||
|  | require ( | ||||||
|  | 	github.com/gin-gonic/gin v1.10.0 | ||||||
|  | 	github.com/glebarez/sqlite v1.11.0 | ||||||
|  | 	github.com/go-acme/lego/v4 v4.23.1 | ||||||
|  | 	gorm.io/gorm v1.26.0 | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | require ( | ||||||
|  | 	github.com/aliyun/alibaba-cloud-sdk-go v1.63.100 // indirect | ||||||
|  | 	github.com/bytedance/sonic v1.11.6 // indirect | ||||||
|  | 	github.com/bytedance/sonic/loader v0.1.1 // indirect | ||||||
|  | 	github.com/cenkalti/backoff/v4 v4.3.0 // indirect | ||||||
|  | 	github.com/cloudwego/base64x v0.1.4 // indirect | ||||||
|  | 	github.com/cloudwego/iasm v0.2.0 // indirect | ||||||
|  | 	github.com/dustin/go-humanize v1.0.1 // indirect | ||||||
|  | 	github.com/gabriel-vasile/mimetype v1.4.3 // indirect | ||||||
|  | 	github.com/gin-contrib/sse v0.1.0 // indirect | ||||||
|  | 	github.com/glebarez/go-sqlite v1.21.2 // indirect | ||||||
|  | 	github.com/go-jose/go-jose/v4 v4.0.5 // indirect | ||||||
|  | 	github.com/go-playground/locales v0.14.1 // indirect | ||||||
|  | 	github.com/go-playground/universal-translator v0.18.1 // indirect | ||||||
|  | 	github.com/go-playground/validator/v10 v10.20.0 // indirect | ||||||
|  | 	github.com/goccy/go-json v0.10.5 // indirect | ||||||
|  | 	github.com/google/uuid v1.6.0 // indirect | ||||||
|  | 	github.com/jinzhu/inflection v1.0.0 // indirect | ||||||
|  | 	github.com/jinzhu/now v1.1.5 // indirect | ||||||
|  | 	github.com/jmespath/go-jmespath v0.4.0 // indirect | ||||||
|  | 	github.com/json-iterator/go v1.1.12 // indirect | ||||||
|  | 	github.com/klauspost/cpuid/v2 v2.2.7 // indirect | ||||||
|  | 	github.com/leodido/go-urn v1.4.0 // indirect | ||||||
|  | 	github.com/mattn/go-isatty v0.0.20 // indirect | ||||||
|  | 	github.com/miekg/dns v1.1.64 // indirect | ||||||
|  | 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||||||
|  | 	github.com/modern-go/reflect2 v1.0.2 // indirect | ||||||
|  | 	github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect | ||||||
|  | 	github.com/pelletier/go-toml/v2 v2.2.2 // indirect | ||||||
|  | 	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||||||
|  | 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||||||
|  | 	github.com/ugorji/go/codec v1.2.12 // indirect | ||||||
|  | 	golang.org/x/arch v0.8.0 // indirect | ||||||
|  | 	golang.org/x/crypto v0.36.0 // indirect | ||||||
|  | 	golang.org/x/mod v0.23.0 // indirect | ||||||
|  | 	golang.org/x/net v0.37.0 // indirect | ||||||
|  | 	golang.org/x/sync v0.12.0 // indirect | ||||||
|  | 	golang.org/x/sys v0.31.0 // indirect | ||||||
|  | 	golang.org/x/text v0.23.0 // indirect | ||||||
|  | 	golang.org/x/tools v0.30.0 // indirect | ||||||
|  | 	google.golang.org/protobuf v1.36.5 // indirect | ||||||
|  | 	gopkg.in/ini.v1 v1.67.0 // indirect | ||||||
|  | 	gopkg.in/yaml.v3 v3.0.1 // indirect | ||||||
|  | 	modernc.org/libc v1.22.5 // indirect | ||||||
|  | 	modernc.org/mathutil v1.5.0 // indirect | ||||||
|  | 	modernc.org/memory v1.5.0 // indirect | ||||||
|  | 	modernc.org/sqlite v1.23.1 // indirect | ||||||
|  | ) | ||||||
							
								
								
									
										191
									
								
								go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								go.sum
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,191 @@ | ||||||
|  | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= | ||||||
|  | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= | ||||||
|  | github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= | ||||||
|  | github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= | ||||||
|  | github.com/aliyun/alibaba-cloud-sdk-go v1.63.100 h1:yUkCbrSM1cWtgBfRVKMQtdt22KhDvKY7g4V+92eG9wA= | ||||||
|  | github.com/aliyun/alibaba-cloud-sdk-go v1.63.100/go.mod h1:SOSDHfe1kX91v3W5QiBsWSLqeLxImobbMX1mxrFHsVQ= | ||||||
|  | github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= | ||||||
|  | github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= | ||||||
|  | github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= | ||||||
|  | github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= | ||||||
|  | github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= | ||||||
|  | github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= | ||||||
|  | github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= | ||||||
|  | github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= | ||||||
|  | github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= | ||||||
|  | github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= | ||||||
|  | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= | ||||||
|  | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||||
|  | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||||
|  | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= | ||||||
|  | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||||
|  | github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= | ||||||
|  | github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= | ||||||
|  | github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= | ||||||
|  | github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= | ||||||
|  | github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= | ||||||
|  | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= | ||||||
|  | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= | ||||||
|  | github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= | ||||||
|  | github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= | ||||||
|  | github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo= | ||||||
|  | github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= | ||||||
|  | github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw= | ||||||
|  | github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= | ||||||
|  | github.com/go-acme/lego/v4 v4.23.1 h1:lZ5fGtGESA2L9FB8dNTvrQUq3/X4QOb8ExkKyY7LSV4= | ||||||
|  | github.com/go-acme/lego/v4 v4.23.1/go.mod h1:7UMVR7oQbIYw6V7mTgGwi4Er7B6Ww0c+c8feiBM0EgI= | ||||||
|  | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= | ||||||
|  | github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE= | ||||||
|  | github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA= | ||||||
|  | github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= | ||||||
|  | github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= | ||||||
|  | github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= | ||||||
|  | github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= | ||||||
|  | github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= | ||||||
|  | github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= | ||||||
|  | github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= | ||||||
|  | github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= | ||||||
|  | github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= | ||||||
|  | github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= | ||||||
|  | github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= | ||||||
|  | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= | ||||||
|  | github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||||||
|  | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||||||
|  | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||||||
|  | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | ||||||
|  | github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= | ||||||
|  | github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= | ||||||
|  | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||||||
|  | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||||
|  | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= | ||||||
|  | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||||||
|  | github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= | ||||||
|  | github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||||||
|  | github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= | ||||||
|  | github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= | ||||||
|  | github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= | ||||||
|  | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= | ||||||
|  | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= | ||||||
|  | github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= | ||||||
|  | github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= | ||||||
|  | github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= | ||||||
|  | github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= | ||||||
|  | github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= | ||||||
|  | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||||||
|  | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||||||
|  | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||||||
|  | github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= | ||||||
|  | github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= | ||||||
|  | github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= | ||||||
|  | github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= | ||||||
|  | github.com/miekg/dns v1.1.64 h1:wuZgD9wwCE6XMT05UU/mlSko71eRSXEAm2EbjQXLKnQ= | ||||||
|  | github.com/miekg/dns v1.1.64/go.mod h1:Dzw9769uoKVaLuODMDZz9M6ynFU6Em65csPuoi8G0ck= | ||||||
|  | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||||||
|  | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= | ||||||
|  | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||||||
|  | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= | ||||||
|  | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= | ||||||
|  | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= | ||||||
|  | github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b h1:FfH+VrHHk6Lxt9HdVS0PXzSXFyS2NbZKXv33FYPol0A= | ||||||
|  | github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b/go.mod h1:AC62GU6hc0BrNm+9RK9VSiwa/EUe1bkIeFORAMcHvJU= | ||||||
|  | github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= | ||||||
|  | github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= | ||||||
|  | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||||||
|  | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||||
|  | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= | ||||||
|  | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||||
|  | github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= | ||||||
|  | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= | ||||||
|  | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= | ||||||
|  | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||||
|  | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||||||
|  | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | ||||||
|  | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= | ||||||
|  | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||||||
|  | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||||
|  | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||||
|  | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||||||
|  | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||||||
|  | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||||||
|  | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||||
|  | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||||||
|  | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||||
|  | github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= | ||||||
|  | github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= | ||||||
|  | github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= | ||||||
|  | github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= | ||||||
|  | github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= | ||||||
|  | github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= | ||||||
|  | go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= | ||||||
|  | golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= | ||||||
|  | golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= | ||||||
|  | golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= | ||||||
|  | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||||
|  | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||||||
|  | golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= | ||||||
|  | golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= | ||||||
|  | golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= | ||||||
|  | golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= | ||||||
|  | golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= | ||||||
|  | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= | ||||||
|  | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= | ||||||
|  | golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= | ||||||
|  | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= | ||||||
|  | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||||||
|  | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= | ||||||
|  | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= | ||||||
|  | golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= | ||||||
|  | golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= | ||||||
|  | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||||
|  | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||||||
|  | golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= | ||||||
|  | golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= | ||||||
|  | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||||
|  | golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= | ||||||
|  | golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= | ||||||
|  | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||||
|  | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||||
|  | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||||
|  | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||||
|  | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||||
|  | golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= | ||||||
|  | golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= | ||||||
|  | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||||
|  | golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= | ||||||
|  | golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= | ||||||
|  | golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||||
|  | golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||||
|  | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||||
|  | golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY= | ||||||
|  | golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY= | ||||||
|  | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||||
|  | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||||
|  | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||||
|  | gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= | ||||||
|  | gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= | ||||||
|  | gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= | ||||||
|  | gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= | ||||||
|  | google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= | ||||||
|  | google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= | ||||||
|  | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||||||
|  | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||||
|  | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||||
|  | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= | ||||||
|  | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= | ||||||
|  | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||||
|  | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||||
|  | gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||||
|  | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||||||
|  | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||||
|  | gorm.io/gorm v1.26.0 h1:9lqQVPG5aNNS6AyHdRiwScAVnXHg/L/Srzx55G5fOgs= | ||||||
|  | gorm.io/gorm v1.26.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= | ||||||
|  | modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE= | ||||||
|  | modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY= | ||||||
|  | modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= | ||||||
|  | modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= | ||||||
|  | modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds= | ||||||
|  | modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= | ||||||
|  | modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM= | ||||||
|  | modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk= | ||||||
|  | nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= | ||||||
|  | rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= | ||||||
							
								
								
									
										52
									
								
								handler/domain.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								handler/domain.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,52 @@ | ||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/model" | ||||||
|  | 	"acme-mana-server-go/service" | ||||||
|  | 	"acme-mana-server-go/vo" | ||||||
|  | 	"github.com/gin-gonic/gin" | ||||||
|  | 	"strconv" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | var domainService = &service.DomainService{} | ||||||
|  | 
 | ||||||
|  | type DomainHandler struct { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (d *DomainHandler) Register(r *gin.RouterGroup) { | ||||||
|  | 	group := r.Group("/domain") | ||||||
|  | 	group.GET("/:id", d.Get) | ||||||
|  | 	group.POST("/", d.Add) | ||||||
|  | 	group.POST("/page", d.Page) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (d *DomainHandler) Add(c *gin.Context) { | ||||||
|  | 	var domain model.Domain | ||||||
|  | 	err := c.ShouldBindJSON(&domain) | ||||||
|  | 	if err != nil { | ||||||
|  | 		c.JSON(200, vo.Fail(err.Error())) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	domainService.Add(&domain) | ||||||
|  | 	c.JSON(200, vo.Success(nil)) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (d *DomainHandler) Get(c *gin.Context) { | ||||||
|  | 	idStr := c.Param("id") | ||||||
|  | 	id, err := strconv.Atoi(idStr) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	domain := domainService.Get(id) | ||||||
|  | 	c.JSON(200, vo.Success(domain)) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (d *DomainHandler) Page(c *gin.Context) { | ||||||
|  | 	req := &vo.DomainPageReq{} | ||||||
|  | 	err := c.ShouldBindJSON(req) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | 	total, list := domainService.Page(req) | ||||||
|  | 	c.JSON(200, vo.Success(vo.PageResult{Total: total, List: list})) | ||||||
|  | } | ||||||
							
								
								
									
										33
									
								
								handler/error.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								handler/error.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | ||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/vo" | ||||||
|  | 	"github.com/gin-gonic/gin" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func GlobalPanicHandler() gin.HandlerFunc { | ||||||
|  | 	return func(ctx *gin.Context) { | ||||||
|  | 		defer func() { | ||||||
|  | 			if err := recover(); err != nil { | ||||||
|  | 				ctx.JSON(500, vo.Fail(err.(error).Error())) | ||||||
|  | 				ctx.Abort() | ||||||
|  | 			} | ||||||
|  | 		}() | ||||||
|  | 		ctx.Next() | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func GlobalErrorHandler() gin.HandlerFunc { | ||||||
|  | 	return func(c *gin.Context) { | ||||||
|  | 		c.Next() | ||||||
|  | 		if len(c.Errors) > 0 { | ||||||
|  | 			c.JSON(500, vo.Fail(c.Errors.String())) | ||||||
|  | 			c.Abort() | ||||||
|  | 		} | ||||||
|  | 		err := recover() | ||||||
|  | 		if err != nil { | ||||||
|  | 			c.JSON(500, vo.Fail(err.(error).Error())) | ||||||
|  | 			c.Abort() | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								handler/handler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								handler/handler.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | ||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import "github.com/gin-gonic/gin" | ||||||
|  | 
 | ||||||
|  | type Handler interface { | ||||||
|  | 	Register(r *gin.RouterGroup) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func RegisterRouter(r *gin.Engine) { | ||||||
|  | 	api := r.Group("/api/v1") | ||||||
|  | 	domainHandler := DomainHandler{} | ||||||
|  | 	domainHandler.Register(api) | ||||||
|  | } | ||||||
							
								
								
									
										1
									
								
								handler/user.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								handler/user.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | ||||||
|  | package handler | ||||||
							
								
								
									
										7
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | ||||||
|  | package main | ||||||
|  | 
 | ||||||
|  | import "acme-mana-server-go/server" | ||||||
|  | 
 | ||||||
|  | func main() { | ||||||
|  | 	server.Start() | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								model/domain.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								model/domain.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | ||||||
|  | package model | ||||||
|  | 
 | ||||||
|  | type Domain struct { | ||||||
|  | 	Id           uint   `gorm:"primary_key;auto_increment"` | ||||||
|  | 	Name         string `gorm:"type:varchar(255);not null"` | ||||||
|  | 	Hosts        string `gorm:"type:varchar(255);not null"` | ||||||
|  | 	Provider     string `gorm:"type:varchar(32);not null"` | ||||||
|  | 	ProviderConf string `gorm:"type:text;not null"` | ||||||
|  | 	AcmeEmail    string `gorm:"type:varchar(255);not null"` | ||||||
|  | 	AcmePriKey   string `gorm:"type:text;not null"` | ||||||
|  | 	Registration string `gorm:"type:text;not null"` | ||||||
|  | 	Resource     string `gorm:"type:text;not null"` | ||||||
|  | } | ||||||
							
								
								
									
										20
									
								
								server/server.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								server/server.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | ||||||
|  | package server | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/config" | ||||||
|  | 	"acme-mana-server-go/handler" | ||||||
|  | 	"github.com/gin-gonic/gin" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func Start() { | ||||||
|  | 	engine := gin.Default() | ||||||
|  | 	engine.Use(gin.Recovery()) | ||||||
|  | 	engine.Use(handler.GlobalPanicHandler()) | ||||||
|  | 	engine.Use(handler.GlobalErrorHandler()) | ||||||
|  | 	handler.RegisterRouter(engine) | ||||||
|  | 	serverConf := config.GetConfig().Server | ||||||
|  | 	err := engine.Run(serverConf.Host + ":" + serverConf.Port) | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										32
									
								
								service/domian.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								service/domian.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | ||||||
|  | package service | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"acme-mana-server-go/dao" | ||||||
|  | 	"acme-mana-server-go/model" | ||||||
|  | 	"acme-mana-server-go/vo" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type DomainService struct { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | var domainDao = &dao.DomainDao{} | ||||||
|  | 
 | ||||||
|  | func (_ *DomainService) Get(id int) *model.Domain { | ||||||
|  | 	return domainDao.Get(id) | ||||||
|  | } | ||||||
|  | func (_ *DomainService) List() []*model.Domain { | ||||||
|  | 	return domainDao.List() | ||||||
|  | } | ||||||
|  | func (_ *DomainService) Add(domain *model.Domain) *model.Domain { | ||||||
|  | 	return domainDao.Add(domain) | ||||||
|  | } | ||||||
|  | func (_ *DomainService) Edit(domain *model.Domain) *model.Domain { | ||||||
|  | 	return domainDao.Edit(domain) | ||||||
|  | } | ||||||
|  | func (_ *DomainService) Delete(id int) { | ||||||
|  | 	domainDao.Delete(id) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (_ *DomainService) Page(req *vo.DomainPageReq) (int64, *[]model.Domain) { | ||||||
|  | 	return domainDao.Page(req) | ||||||
|  | } | ||||||
							
								
								
									
										5
									
								
								util/ReqUtil.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								util/ReqUtil.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | package util | ||||||
|  | 
 | ||||||
|  | func ParsePageReq(body string) { | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										11
									
								
								util/env_util.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								util/env_util.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | ||||||
|  | package util | ||||||
|  | 
 | ||||||
|  | import "os" | ||||||
|  | 
 | ||||||
|  | func GetEnv(name string, defaultValue string) string { | ||||||
|  | 	value := os.Getenv(name) | ||||||
|  | 	if value == "" { | ||||||
|  | 		return defaultValue | ||||||
|  | 	} | ||||||
|  | 	return value | ||||||
|  | } | ||||||
							
								
								
									
										8
									
								
								vo/domain.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								vo/domain.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | ||||||
|  | package vo | ||||||
|  | 
 | ||||||
|  | type DomainPageReq struct { | ||||||
|  | 	Bean struct { | ||||||
|  | 		Name string `json:"name"` | ||||||
|  | 	} | ||||||
|  | 	Page Page | ||||||
|  | } | ||||||
							
								
								
									
										11
									
								
								vo/page.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vo/page.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | ||||||
|  | package vo | ||||||
|  | 
 | ||||||
|  | type Page struct { | ||||||
|  | 	Page int `json:"page"` | ||||||
|  | 	Size int `json:"size"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | type PageResult struct { | ||||||
|  | 	Total int64       `json:"total"` | ||||||
|  | 	List  interface{} `json:"list"` | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								vo/result.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								vo/result.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | ||||||
|  | package vo | ||||||
|  | 
 | ||||||
|  | type Result struct { | ||||||
|  | 	Code int         `json:"code"` | ||||||
|  | 	Msg  string      `json:"msg"` | ||||||
|  | 	Data interface{} `json:"data"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func Success(data interface{}) *Result { | ||||||
|  | 	return &Result{ | ||||||
|  | 		Code: 200, | ||||||
|  | 		Msg:  "success", | ||||||
|  | 		Data: data, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func Fail(msg string) *Result { | ||||||
|  | 	return &Result{ | ||||||
|  | 		Code: 400, | ||||||
|  | 		Msg:  msg, | ||||||
|  | 		Data: nil, | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user