-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.go
41 lines (32 loc) · 1.01 KB
/
generate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package http
import (
"github.com/alexfalkowski/bezeichner/server/ids"
"github.com/alexfalkowski/go-service/meta"
nh "github.com/alexfalkowski/go-service/net/http"
)
type (
// GenerateIdentifiersRequest for a specific application.
GenerateIdentifiersRequest struct {
Application string `json:"application,omitempty"`
Count uint64 `json:"count,omitempty"`
}
// GenerateIdentifiersResponse for a specific application.
GenerateIdentifiersResponse struct {
Meta map[string]string `json:"meta,omitempty"`
IDs []string `json:"ids,omitempty"`
}
generateHandler struct {
service *ids.Identifier
}
)
func (h *generateHandler) Handle(ctx nh.Context, req *GenerateIdentifiersRequest) (*GenerateIdentifiersResponse, error) {
resp := &GenerateIdentifiersResponse{}
ids, err := h.service.Generate(ctx, req.Application, req.Count)
if err != nil {
resp.Meta = meta.CamelStrings(ctx, "")
return resp, handleError(err)
}
resp.IDs = ids
resp.Meta = meta.CamelStrings(ctx, "")
return resp, nil
}