mirror of
				https://github.com/eolinker/apinto
				synced 2025-10-31 20:12:56 +08:00 
			
		
		
		
	额外参数新增uuid算法
This commit is contained in:
		| @@ -5,6 +5,8 @@ import ( | ||||
| 	"strings" | ||||
| 	"sync" | ||||
|  | ||||
| 	"github.com/eolinker/apinto/drivers/plugins/extra-params_v2/dynamic-params/uuid" | ||||
|  | ||||
| 	hmac_sha256 "github.com/eolinker/apinto/drivers/plugins/extra-params_v2/dynamic-params/hmac-sha256" | ||||
|  | ||||
| 	"github.com/eolinker/apinto/drivers/plugins/extra-params_v2/dynamic-params/concat" | ||||
| @@ -55,6 +57,7 @@ func Create(id, name string, conf *Config, workers map[eosc.RequireId]eosc.IWork | ||||
| 		timestamp.Register() | ||||
| 		concat.Register() | ||||
| 		hmac_sha256.Register() | ||||
| 		uuid.Register() | ||||
| 	}) | ||||
| 	ep := &executor{ | ||||
| 		WorkerBase:      drivers.Worker(id, name), | ||||
|   | ||||
| @@ -0,0 +1,24 @@ | ||||
| package uuid | ||||
|  | ||||
| import dynamic_params "github.com/eolinker/apinto/drivers/plugins/extra-params_v2/dynamic-params" | ||||
|  | ||||
| const name = "$uuid" | ||||
|  | ||||
| func Register() { | ||||
| 	dynamic_params.Register(name, NewFactory()) | ||||
| } | ||||
|  | ||||
| func NewFactory() *Factory { | ||||
| 	return &Factory{} | ||||
| } | ||||
|  | ||||
| type Factory struct { | ||||
| } | ||||
|  | ||||
| func (f *Factory) Create(name string, value []string) (dynamic_params.IDynamicDriver, error) { | ||||
| 	v := defaultValue | ||||
| 	if len(value) > 0 { | ||||
| 		v = value[0] | ||||
| 	} | ||||
| 	return NewUuid(name, v), nil | ||||
| } | ||||
							
								
								
									
										34
									
								
								drivers/plugins/extra-params_v2/dynamic-params/uuid/uuid.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								drivers/plugins/extra-params_v2/dynamic-params/uuid/uuid.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| package uuid | ||||
|  | ||||
| import ( | ||||
| 	"github.com/google/uuid" | ||||
|  | ||||
| 	http_service "github.com/eolinker/eosc/eocontext/http-context" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	defaultValue = "string" | ||||
| ) | ||||
|  | ||||
| type Uuid struct { | ||||
| 	name  string | ||||
| 	value string | ||||
| } | ||||
|  | ||||
| func NewUuid(name, value string) *Uuid { | ||||
| 	return &Uuid{name: name, value: value} | ||||
| } | ||||
|  | ||||
| func (t *Uuid) Name() string { | ||||
| 	return t.name | ||||
| } | ||||
|  | ||||
| func (t *Uuid) Generate(ctx http_service.IHttpContext, contentType string, args ...interface{}) (interface{}, error) { | ||||
| 	switch t.value { | ||||
| 	case "string": | ||||
| 		return uuid.New().String(), nil | ||||
| 	case "int": | ||||
| 		return uuid.New().ID(), nil | ||||
| 	} | ||||
| 	return uuid.New().String(), nil | ||||
| } | ||||
| @@ -69,7 +69,7 @@ func (ur *URIRequest) GetQuery(key string) string { | ||||
| } | ||||
|  | ||||
| func (ur *URIRequest) RawQuery() string { | ||||
| 	return string(ur.uri.QueryString()) | ||||
| 	return string(ur.uri.QueryArgs().String()) | ||||
| } | ||||
|  | ||||
| func (ur *URIRequest) SetPath(s string) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Liujian
					Liujian