main.go 978 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // +build codegen
  2. // Command aws-gen-goendpoints parses a JSON description of the AWS endpoint
  3. // discovery logic and generates a Go file which returns an endpoint.
  4. //
  5. // aws-gen-goendpoints apis/_endpoints.json aws/endpoints_map.go
  6. package main
  7. import (
  8. "encoding/json"
  9. "os"
  10. "github.com/aws/aws-sdk-go/private/model"
  11. )
  12. // Generates the endpoints from json description
  13. //
  14. // CLI Args:
  15. // [0] This file's execution path
  16. // [1] The definition file to use
  17. // [2] The output file to generate
  18. func main() {
  19. in, err := os.Open(os.Args[1])
  20. if err != nil {
  21. panic(err)
  22. }
  23. defer in.Close()
  24. var endpoints struct {
  25. Version int
  26. Endpoints map[string]struct {
  27. Endpoint string
  28. SigningRegion string
  29. }
  30. }
  31. if err = json.NewDecoder(in).Decode(&endpoints); err != nil {
  32. panic(err)
  33. }
  34. out, err := os.Create(os.Args[2])
  35. if err != nil {
  36. panic(err)
  37. }
  38. defer out.Close()
  39. if err := model.GenerateEndpoints(endpoints, out); err != nil {
  40. panic(err)
  41. }
  42. }