- 新增 ACME客户端功能,支持域名注册和证书申请 - 添加数据库模型和操作,用于存储和管理域名信息 - 实现 API 接口,提供域名注册、获取和分页查询功能 -集成全局错误处理和 panic捕获 - 添加单元测试和集成测试
40 lines
830 B
Go
40 lines
830 B
Go
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()
|
|
}
|