mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	
		
			
	
	
		
			50 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			50 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| 
								 | 
							
								package acme
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import (
							 | 
						||
| 
								 | 
							
									"crypto"
							 | 
						||
| 
								 | 
							
									"encoding/json"
							 | 
						||
| 
								 | 
							
									"github.com/go-acme/lego/v4/registration"
							 | 
						||
| 
								 | 
							
								)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								type User struct {
							 | 
						||
| 
								 | 
							
									email        string
							 | 
						||
| 
								 | 
							
									resource     *registration.Resource
							 | 
						||
| 
								 | 
							
									key          crypto.PrivateKey
							 | 
						||
| 
								 | 
							
									registerFunc func(resource *registration.Resource) error
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func NewUser(email string, key crypto.PrivateKey, registerFunc func(resource *registration.Resource) error) *User {
							 | 
						||
| 
								 | 
							
									return &User{
							 | 
						||
| 
								 | 
							
										email:        email,
							 | 
						||
| 
								 | 
							
										key:          key,
							 | 
						||
| 
								 | 
							
										registerFunc: registerFunc,
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (this *User) GetEmail() string {
							 | 
						||
| 
								 | 
							
									return this.email
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (this *User) GetRegistration() *registration.Resource {
							 | 
						||
| 
								 | 
							
									return this.resource
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (this *User) SetRegistration(resourceData []byte) error {
							 | 
						||
| 
								 | 
							
									resource := ®istration.Resource{}
							 | 
						||
| 
								 | 
							
									err := json.Unmarshal(resourceData, resource)
							 | 
						||
| 
								 | 
							
									if err != nil {
							 | 
						||
| 
								 | 
							
										return err
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									this.resource = resource
							 | 
						||
| 
								 | 
							
									return nil
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (this *User) GetPrivateKey() crypto.PrivateKey {
							 | 
						||
| 
								 | 
							
									return this.key
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (this *User) Register(resource *registration.Resource) error {
							 | 
						||
| 
								 | 
							
									this.resource = resource
							 | 
						||
| 
								 | 
							
									return this.registerFunc(resource)
							 | 
						||
| 
								 | 
							
								}
							 |