main.go 959 B

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