forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoints.go
57 lines (47 loc) · 1.08 KB
/
endpoints.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package model
import (
"bytes"
"go/format"
"io"
"text/template"
)
// GenerateEndpoints writes a Go file to the given writer.
func GenerateEndpoints(endpoints interface{}, w io.Writer) error {
tmpl, err := template.New("endpoints").Parse(t)
if err != nil {
return err
}
out := bytes.NewBuffer(nil)
if err = tmpl.Execute(out, endpoints); err != nil {
return err
}
b, err := format.Source(bytes.TrimSpace(out.Bytes()))
if err != nil {
return err
}
_, err = io.Copy(w, bytes.NewReader(b))
return err
}
const t = `
package endpoints
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
type endpointStruct struct {
Version int
Endpoints map[string]endpointEntry
}
type endpointEntry struct {
Endpoint string
SigningRegion string
}
var endpointsMap = endpointStruct{
Version: {{ .Version }},
Endpoints: map[string]endpointEntry{
{{ range $key, $entry := .Endpoints }}"{{ $key }}": endpointEntry{
Endpoint: "{{ $entry.Endpoint }}",
{{ if ne $entry.SigningRegion "" }}SigningRegion: "{{ $entry.SigningRegion }}",
{{ end }}
},
{{ end }}
},
}
`