Commit df45f0ec authored by harry's avatar harry

init

parents
Pipeline #14936 failed with stages
package gis
// GetGeoInfoInput get geo info input struct
type GetGeoInfoInput struct {
APIKey string `json:"api_key,omitempty"`
IP string `json:"ip,omitempty"`
IPs []string `json:"ips,omitempty"`
}
package gis
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// SendV1GeoInfoJSONRequest send v1 geo info json request
func (s *GIS) SendV1GeoInfoJSONRequest(input *GetGeoInfoInput) (json.RawMessage, error) {
// New url
url := s.Host.String() + "/v1/geoinfo.json?ip=" + input.IP
// New request
req, err := http.NewRequest("GET", url, nil)
req.Header.Set("Accept", "application/json")
// Set api key
if len(input.APIKey) > 0 {
req.Header.Set("X-Api-Key", input.APIKey)
}
// Send request
resp, err := s.Client.Do(req)
if err != nil {
return nil, err
}
respBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, err
}
return respBody, nil
}
// SendV1GeoInfoRequest send v1 geo info request
func (s *GIS) SendV1GeoInfoRequest(input *GetGeoInfoInput) (map[string]*GeoInfo, error) {
// Send json request
respBody, err := s.SendV1GeoInfoJSONRequest(input)
if err != nil {
return nil, err
}
// Parse body
var geoInfos map[string]*GeoInfo
if err := jsonex.Unmarshal(respBody, &geoInfos); err != nil {
return nil, err
}
return geoInfos, nil
}
// SendV2GeoInfoJSONRequest send v2 geo info json request
func (s *GIS) SendV2GeoInfoJSONRequest(input *GetGeoInfoInput) (json.RawMessage, error) {
// New url
url := s.Host.String() + "/v2/geoinfo.json?ip=" + input.IP
// New request
req, err := http.NewRequest("GET", url, nil)
req.Header.Set("Accept", "application/json")
// Set api key
if len(input.APIKey) > 0 {
req.Header.Set("X-Api-Key", input.APIKey)
}
// Send request
resp, err := s.Client.Do(req)
if err != nil {
return nil, err
}
respBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, err
}
return respBody, nil
}
// SendV2GeoInfoRequest send v2 geo info request
func (s *GIS) SendV2GeoInfoRequest(input *GetGeoInfoInput) (*GeoInfo, error) {
// Send json request
respBody, err := s.SendV2GeoInfoJSONRequest(input)
if err != nil {
return nil, err
}
// Parse body
geoInfo := new(GeoInfo)
if err := jsonex.Unmarshal(respBody, geoInfo); err != nil {
return nil, err
}
return geoInfo, nil
}
package gis
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
)
// SendV1GeoInfosJSONRequest send v1 geo infos json request
func (s *GIS) SendV1GeoInfosJSONRequest(input *GetGeoInfoInput) (json.RawMessage, error) {
// New url
url := s.Host.String() + "/v1/geoinfos.json"
// New request body
data, err := jsonex.Marshal(input.IPs)
if err != nil {
return nil, err
}
// New request
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
// Set api key
if len(input.APIKey) > 0 {
req.Header.Set("X-Api-Key", input.APIKey)
}
// Send request
resp, err := s.Client.Do(req)
if err != nil {
return nil, err
}
respBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, err
}
return respBody, nil
}
// SendV1GeoInfosRequest send v1 geo infos request
func (s *GIS) SendV1GeoInfosRequest(input *GetGeoInfoInput) (map[string]*GeoInfo, error) {
// Send json request
respBody, err := s.SendV1GeoInfosJSONRequest(input)
if err != nil {
return nil, err
}
// Parse body
var geoInfos map[string]*GeoInfo
if err := jsonex.Unmarshal(respBody, &geoInfos); err != nil {
return nil, err
}
return geoInfos, nil
}
// SendV2GeoInfosJSONRequest send v2 geo infos json request
func (s *GIS) SendV2GeoInfosJSONRequest(input *GetGeoInfoInput) (json.RawMessage, error) {
// New url
url := s.Host.String() + "/v2/geoinfos.json"
// New request body
data, err := jsonex.Marshal(IPsResource{input.IPs})
if err != nil {
return nil, err
}
// New request
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
// Set api key
if len(input.APIKey) > 0 {
req.Header.Set("X-Api-Key", input.APIKey)
}
// Send request
resp, err := s.Client.Do(req)
if err != nil {
return nil, err
}
respBody, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, err
}
return respBody, nil
}
// SendV2GeoInfosRequest send v2 geo infos request
func (s *GIS) SendV2GeoInfosRequest(input *GetGeoInfoInput) (*GeoInfosResource, error) {
// Send json request
respBody, err := s.SendV2GeoInfosJSONRequest(input)
if err != nil {
return nil, err
}
// Parse body
geoInfos := new(GeoInfosResource)
if err := jsonex.Unmarshal(respBody, geoInfos); err != nil {
return nil, err
}
return geoInfos, nil
}
package gis
// Client gis client
var Client *GIS
// InitClient init gis client
func InitClient() {
Client = New()
}
package gis
import "os"
var endpoint = os.Getenv("GIS_ENDPOINT")
var apiKey = os.Getenv("GIS_API_KEY")
// SetEndpoint set endpoint
func SetEndpoint(s string) {
endpoint = s
}
// SetAPIKey set api key
func SetAPIKey(s string) {
apiKey = s
}
package gis
// GeoInfo geo info struct
type GeoInfo struct {
IP float64 `json:"ip,omitempty"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
ContinentName string `json:"continent_name,omitempty"`
ContinentCode string `json:"continent_code,omitempty"`
CountryName string `json:"country_name,omitempty"`
CountryIsoCode string `json:"country_iso_code,omitempty"`
CityName string `json:"city_name,omitempty"`
TimeZone string `json:"time_zone,omitempty"`
Coordinates string `json:"coordinates,omitempty"`
}
// GeoInfosResource geo infos resource struct
type GeoInfosResource struct {
GeoInfos []*GeoInfo `json:"geo_infos,omitempty"`
}
// IPsResource ips resource struct
type IPsResource struct {
IPs []string `json:"ips,omitempty"`
}
package gis
import "github.com/json-iterator/go"
var jsonex = jsoniter.ConfigCompatibleWithStandardLibrary
package gis
import (
"net/http"
"net/url"
"time"
)
// GIS service struct
type GIS struct {
Client *http.Client
Host *url.URL
}
// New get Service instance
func New() *GIS {
svc := &GIS{
Client: &http.Client{
Timeout: time.Duration(5 * time.Second),
Transport: &Transport{},
},
Host: &url.URL{
Scheme: "http",
Host: endpoint,
},
}
return svc
}
// Transport token transport
type Transport struct{}
// RoundTrip http Transport RoundTrip interface
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
if len(apiKey) > 0 {
req.Header.Set("X-Api-Key", apiKey)
}
return http.DefaultTransport.RoundTrip(req)
}
// Code generated by github.com/chouandy/goex/awsex/gen-api/main.go. DO NOT EDIT.
package gisapi
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/private/protocol"
"github.com/chouandy/goex/awsex/awsutil"
)
const opV1GetGeoInfo = "V1GetGeoInfo"
// V1GetGeoInfoRequest is a API request type for the V1GetGeoInfo API operation.
type V1GetGeoInfoRequest struct {
*aws.Request
Input *V1GetGeoInfoInput
Copy func(*V1GetGeoInfoInput) V1GetGeoInfoRequest
}
// Send marshals and sends the V1GetGeoInfo API request.
func (r V1GetGeoInfoRequest) Send() (*V1GetGeoInfoOutput, error) {
err := r.Request.Send()
if err != nil {
return nil, err
}
return r.Request.Data.(*V1GetGeoInfoOutput), nil
}
// V1GetGeoInfoRequest returns a request value for making API operation for
// GISAPI.
//
// // Example sending a request using the V1GetGeoInfoRequest method.
// req := client.V1GetGeoInfoRequest(params)
// resp, err := req.Send()
// if err == nil {
// fmt.Println(resp)
// }
//
func (c *GISAPI) V1GetGeoInfoRequest(input *V1GetGeoInfoInput) V1GetGeoInfoRequest {
op := &aws.Operation{
Name: opV1GetGeoInfo,
HTTPMethod: "GET",
HTTPPath: "/v1/geoinfo.json",
}
if input == nil {
input = &V1GetGeoInfoInput{}
}
output := &V1GetGeoInfoOutput{}
req := c.newRequest(op, input, output)
output.responseMetadata = aws.Response{Request: req}
return V1GetGeoInfoRequest{Request: req, Input: input, Copy: c.V1GetGeoInfoRequest}
}
const opV1GetGeoInfos = "V1GetGeoInfos"
// V1GetGeoInfosRequest is a API request type for the V1GetGeoInfos API operation.
type V1GetGeoInfosRequest struct {
*aws.Request
Input *V1GetGeoInfosInput
Copy func(*V1GetGeoInfosInput) V1GetGeoInfosRequest
}
// Send marshals and sends the V1GetGeoInfos API request.
func (r V1GetGeoInfosRequest) Send() (*V1GetGeoInfosOutput, error) {
err := r.Request.Send()
if err != nil {
return nil, err
}
return r.Request.Data.(*V1GetGeoInfosOutput), nil
}
// V1GetGeoInfosRequest returns a request value for making API operation for
// GISAPI.
//
// // Example sending a request using the V1GetGeoInfosRequest method.
// req := client.V1GetGeoInfosRequest(params)
// resp, err := req.Send()
// if err == nil {
// fmt.Println(resp)
// }
//
func (c *GISAPI) V1GetGeoInfosRequest(input *V1GetGeoInfosInput) V1GetGeoInfosRequest {
op := &aws.Operation{
Name: opV1GetGeoInfos,
HTTPMethod: "POST",
HTTPPath: "/v1/geoinfos.json",
}
if input == nil {
input = &V1GetGeoInfosInput{}
}
output := &V1GetGeoInfosOutput{}
req := c.newRequest(op, input, output)
output.responseMetadata = aws.Response{Request: req}
return V1GetGeoInfosRequest{Request: req, Input: input, Copy: c.V1GetGeoInfosRequest}
}
const opV2GetGeoInfo = "V2GetGeoInfo"
// V2GetGeoInfoRequest is a API request type for the V2GetGeoInfo API operation.
type V2GetGeoInfoRequest struct {
*aws.Request
Input *V2GetGeoInfoInput
Copy func(*V2GetGeoInfoInput) V2GetGeoInfoRequest
}
// Send marshals and sends the V2GetGeoInfo API request.
func (r V2GetGeoInfoRequest) Send() (*V2GetGeoInfoOutput, error) {
err := r.Request.Send()
if err != nil {
return nil, err
}
return r.Request.Data.(*V2GetGeoInfoOutput), nil
}
// V2GetGeoInfoRequest returns a request value for making API operation for
// GISAPI.
//
// // Example sending a request using the V2GetGeoInfoRequest method.
// req := client.V2GetGeoInfoRequest(params)
// resp, err := req.Send()
// if err == nil {
// fmt.Println(resp)
// }
//
func (c *GISAPI) V2GetGeoInfoRequest(input *V2GetGeoInfoInput) V2GetGeoInfoRequest {
op := &aws.Operation{
Name: opV2GetGeoInfo,
HTTPMethod: "GET",
HTTPPath: "/v2/geoinfo.json",
}
if input == nil {
input = &V2GetGeoInfoInput{}
}
output := &V2GetGeoInfoOutput{}
req := c.newRequest(op, input, output)
output.responseMetadata = aws.Response{Request: req}
return V2GetGeoInfoRequest{Request: req, Input: input, Copy: c.V2GetGeoInfoRequest}
}
const opV2GetGeoInfos = "V2GetGeoInfos"
// V2GetGeoInfosRequest is a API request type for the V2GetGeoInfos API operation.
type V2GetGeoInfosRequest struct {
*aws.Request
Input *V2GetGeoInfosInput
Copy func(*V2GetGeoInfosInput) V2GetGeoInfosRequest
}
// Send marshals and sends the V2GetGeoInfos API request.
func (r V2GetGeoInfosRequest) Send() (*V2GetGeoInfosOutput, error) {
err := r.Request.Send()
if err != nil {
return nil, err
}
return r.Request.Data.(*V2GetGeoInfosOutput), nil
}
// V2GetGeoInfosRequest returns a request value for making API operation for
// GISAPI.
//
// // Example sending a request using the V2GetGeoInfosRequest method.
// req := client.V2GetGeoInfosRequest(params)
// resp, err := req.Send()
// if err == nil {
// fmt.Println(resp)
// }
//
func (c *GISAPI) V2GetGeoInfosRequest(input *V2GetGeoInfosInput) V2GetGeoInfosRequest {
op := &aws.Operation{
Name: opV2GetGeoInfos,
HTTPMethod: "POST",
HTTPPath: "/v2/geoinfos.json",
}
if input == nil {
input = &V2GetGeoInfosInput{}
}
output := &V2GetGeoInfosOutput{}
req := c.newRequest(op, input, output)
output.responseMetadata = aws.Response{Request: req}
return V2GetGeoInfosRequest{Request: req, Input: input, Copy: c.V2GetGeoInfosRequest}
}
// GeoInfo GeoInfo struct
type GeoInfo struct {
_ struct{} `type:"structure"`
CityName *string `locationName:"city_name" type:"string" json:"city_name,omitempty"`
ContinentCode *string `locationName:"continent_code" type:"string" json:"continent_code,omitempty"`
ContinentName *string `locationName:"continent_name" type:"string" json:"continent_name,omitempty"`
Coordinates *string `locationName:"coordinates" type:"string" json:"coordinates,omitempty"`
CountryIsoCode *string `locationName:"country_iso_code" type:"string" json:"country_iso_code,omitempty"`
CountryName *string `locationName:"country_name" type:"string" json:"country_name,omitempty"`
IP *string `locationName:"ip" type:"string" json:"ip,omitempty"`
Latitude *float64 `locationName:"latitude" type:"float" json:"latitude,omitempty"`
Longitude *float64 `locationName:"longitude" type:"float" json:"longitude,omitempty"`
TimeZone *string `locationName:"time_zone" type:"string" json:"time_zone,omitempty"`
}
// String returns the string representation
func (s GeoInfo) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s GeoInfo) GoString() string {
return s.String()
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s GeoInfo) MarshalFields(e protocol.FieldEncoder) error {
if s.CityName != nil {
v := *s.CityName
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "city_name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.ContinentCode != nil {
v := *s.ContinentCode
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "continent_code", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.ContinentName != nil {
v := *s.ContinentName
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "continent_name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.Coordinates != nil {
v := *s.Coordinates
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "coordinates", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.CountryIsoCode != nil {
v := *s.CountryIsoCode
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "country_iso_code", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.CountryName != nil {
v := *s.CountryName
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "country_name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.IP != nil {
v := *s.IP
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "ip", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.Latitude != nil {
v := *s.Latitude
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "latitude", protocol.Float64Value(v), metadata)
}
if s.Longitude != nil {
v := *s.Longitude
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "longitude", protocol.Float64Value(v), metadata)
}
if s.TimeZone != nil {
v := *s.TimeZone
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "time_zone", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
return nil
}
// V1GetGeoInfoInput V1GetGeoInfoInput struct
type V1GetGeoInfoInput struct {
_ struct{} `type:"structure"`
// IP is a required field
IP *string `location:"querystring" locationName:"ip" type:"string" required:"true"`
}
// String returns the string representation
func (s V1GetGeoInfoInput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V1GetGeoInfoInput) GoString() string {
return s.String()
}
// Validate inspects the fields of the type to determine if they are valid.
func (s *V1GetGeoInfoInput) Validate() error {
invalidParams := aws.ErrInvalidParams{Context: "V1GetGeoInfoInput"}
if s.IP == nil {
invalidParams.Add(aws.NewErrParamRequired("IP"))
}
if invalidParams.Len() > 0 {
return invalidParams
}
return nil
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V1GetGeoInfoInput) MarshalFields(e protocol.FieldEncoder) error {
if s.IP != nil {
v := *s.IP
metadata := protocol.Metadata{}
e.SetValue(protocol.QueryTarget, "ip", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
return nil
}
// V1GetGeoInfoOutput V1GetGeoInfoOutput struct
type V1GetGeoInfoOutput struct {
_ struct{} `type:"structure" payload:"Body"`
responseMetadata aws.Response
Body []byte `type:"blob"`
}
// String returns the string representation
func (s V1GetGeoInfoOutput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V1GetGeoInfoOutput) GoString() string {
return s.String()
}
// SDKResponseMetdata return sthe response metadata for the API.
func (s V1GetGeoInfoOutput) SDKResponseMetadata() aws.Response {
return s.responseMetadata
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V1GetGeoInfoOutput) MarshalFields(e protocol.FieldEncoder) error {
if s.Body != nil {
v := s.Body
metadata := protocol.Metadata{}
e.SetStream(protocol.PayloadTarget, "Body", protocol.BytesStream(v), metadata)
}
return nil
}
// V1GetGeoInfosInput V1GetGeoInfosInput struct
type V1GetGeoInfosInput struct {
_ struct{} `type:"structure" payload:"Body"`
// Body is a required field
Body []byte `type:"blob" required:"true"`
}
// String returns the string representation
func (s V1GetGeoInfosInput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V1GetGeoInfosInput) GoString() string {
return s.String()
}
// Validate inspects the fields of the type to determine if they are valid.
func (s *V1GetGeoInfosInput) Validate() error {
invalidParams := aws.ErrInvalidParams{Context: "V1GetGeoInfosInput"}
if s.Body == nil {
invalidParams.Add(aws.NewErrParamRequired("Body"))
}
if invalidParams.Len() > 0 {
return invalidParams
}
return nil
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V1GetGeoInfosInput) MarshalFields(e protocol.FieldEncoder) error {
if s.Body != nil {
v := s.Body
metadata := protocol.Metadata{}
e.SetStream(protocol.PayloadTarget, "Body", protocol.BytesStream(v), metadata)
}
return nil
}
// V1GetGeoInfosOutput V1GetGeoInfosOutput struct
type V1GetGeoInfosOutput struct {
_ struct{} `type:"structure" payload:"Body"`
responseMetadata aws.Response
Body []byte `type:"blob"`
}
// String returns the string representation
func (s V1GetGeoInfosOutput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V1GetGeoInfosOutput) GoString() string {
return s.String()
}
// SDKResponseMetdata return sthe response metadata for the API.
func (s V1GetGeoInfosOutput) SDKResponseMetadata() aws.Response {
return s.responseMetadata
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V1GetGeoInfosOutput) MarshalFields(e protocol.FieldEncoder) error {
if s.Body != nil {
v := s.Body
metadata := protocol.Metadata{}
e.SetStream(protocol.PayloadTarget, "Body", protocol.BytesStream(v), metadata)
}
return nil
}
// V2GetGeoInfoInput V2GetGeoInfoInput struct
type V2GetGeoInfoInput struct {
_ struct{} `type:"structure"`
// IP is a required field
IP *string `location:"querystring" locationName:"ip" type:"string" required:"true"`
}
// String returns the string representation
func (s V2GetGeoInfoInput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V2GetGeoInfoInput) GoString() string {
return s.String()
}
// Validate inspects the fields of the type to determine if they are valid.
func (s *V2GetGeoInfoInput) Validate() error {
invalidParams := aws.ErrInvalidParams{Context: "V2GetGeoInfoInput"}
if s.IP == nil {
invalidParams.Add(aws.NewErrParamRequired("IP"))
}
if invalidParams.Len() > 0 {
return invalidParams
}
return nil
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V2GetGeoInfoInput) MarshalFields(e protocol.FieldEncoder) error {
if s.IP != nil {
v := *s.IP
metadata := protocol.Metadata{}
e.SetValue(protocol.QueryTarget, "ip", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
return nil
}
// V2GetGeoInfoOutput V2GetGeoInfoOutput struct
type V2GetGeoInfoOutput struct {
_ struct{} `type:"structure"`
responseMetadata aws.Response
CityName *string `locationName:"city_name" type:"string" json:"city_name,omitempty"`
ContinentCode *string `locationName:"continent_code" type:"string" json:"continent_code,omitempty"`
ContinentName *string `locationName:"continent_name" type:"string" json:"continent_name,omitempty"`
Coordinates *string `locationName:"coordinates" type:"string" json:"coordinates,omitempty"`
CountryIsoCode *string `locationName:"country_iso_code" type:"string" json:"country_iso_code,omitempty"`
CountryName *string `locationName:"country_name" type:"string" json:"country_name,omitempty"`
IP *string `locationName:"ip" type:"string" json:"ip,omitempty"`
Latitude *float64 `locationName:"latitude" type:"float" json:"latitude,omitempty"`
Longitude *float64 `locationName:"longitude" type:"float" json:"longitude,omitempty"`
TimeZone *string `locationName:"time_zone" type:"string" json:"time_zone,omitempty"`
}
// String returns the string representation
func (s V2GetGeoInfoOutput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V2GetGeoInfoOutput) GoString() string {
return s.String()
}
// SDKResponseMetdata return sthe response metadata for the API.
func (s V2GetGeoInfoOutput) SDKResponseMetadata() aws.Response {
return s.responseMetadata
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V2GetGeoInfoOutput) MarshalFields(e protocol.FieldEncoder) error {
if s.CityName != nil {
v := *s.CityName
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "city_name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.ContinentCode != nil {
v := *s.ContinentCode
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "continent_code", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.ContinentName != nil {
v := *s.ContinentName
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "continent_name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.Coordinates != nil {
v := *s.Coordinates
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "coordinates", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.CountryIsoCode != nil {
v := *s.CountryIsoCode
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "country_iso_code", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.CountryName != nil {
v := *s.CountryName
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "country_name", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.IP != nil {
v := *s.IP
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "ip", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.Latitude != nil {
v := *s.Latitude
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "latitude", protocol.Float64Value(v), metadata)
}
if s.Longitude != nil {
v := *s.Longitude
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "longitude", protocol.Float64Value(v), metadata)
}
if s.TimeZone != nil {
v := *s.TimeZone
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "time_zone", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
return nil
}
// V2GetGeoInfosInput V2GetGeoInfosInput struct
type V2GetGeoInfosInput struct {
_ struct{} `type:"structure"`
// IPs is a required field
IPs []string `locationName:"ips" type:"list" required:"true"`
}
// String returns the string representation
func (s V2GetGeoInfosInput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V2GetGeoInfosInput) GoString() string {
return s.String()
}
// Validate inspects the fields of the type to determine if they are valid.
func (s *V2GetGeoInfosInput) Validate() error {
invalidParams := aws.ErrInvalidParams{Context: "V2GetGeoInfosInput"}
if s.IPs == nil {
invalidParams.Add(aws.NewErrParamRequired("IPs"))
}
if invalidParams.Len() > 0 {
return invalidParams
}
return nil
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V2GetGeoInfosInput) MarshalFields(e protocol.FieldEncoder) error {
if len(s.IPs) > 0 {
v := s.IPs
metadata := protocol.Metadata{}
ls0 := e.List(protocol.BodyTarget, "ips", metadata)
ls0.Start()
for _, v1 := range v {
ls0.ListAddValue(protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)})
}
ls0.End()
}
return nil
}
// V2GetGeoInfosOutput V2GetGeoInfosOutput struct
type V2GetGeoInfosOutput struct {
_ struct{} `type:"structure"`
responseMetadata aws.Response
GeoInfos []GeoInfo `locationName:"geo_infos" type:"list"`
}
// String returns the string representation
func (s V2GetGeoInfosOutput) String() string {
return awsutil.Prettify(s)
}
// GoString returns the string representation
func (s V2GetGeoInfosOutput) GoString() string {
return s.String()
}
// SDKResponseMetdata return sthe response metadata for the API.
func (s V2GetGeoInfosOutput) SDKResponseMetadata() aws.Response {
return s.responseMetadata
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s V2GetGeoInfosOutput) MarshalFields(e protocol.FieldEncoder) error {
if len(s.GeoInfos) > 0 {
v := s.GeoInfos
metadata := protocol.Metadata{}
ls0 := e.List(protocol.BodyTarget, "geo_infos", metadata)
ls0.Start()
for _, v1 := range v {
ls0.ListAddFields(v1)
}
ls0.End()
}
return nil
}
// Code generated by github.com/chouandy/goex/awsex/gen-api/main.go. DO NOT EDIT.
package gisapi
import (
"errors"
"fmt"
"os"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/chouandy/goex/awsex/service/apigatewayex"
"github.com/chouandy/goex/awsex/service/sfnex"
"github.com/chouandy/goex/httpex"
)
// Client gisapi client
var Client *GISAPI
// InitClient init gisapi client
func InitClient() error {
cfg, err := external.LoadDefaultAWSConfig()
if err != nil {
return err
}
cfg.Region = os.Getenv("REGION")
Client = New(cfg)
return nil
}
// InitClientMiddleware init gisapi client middleware
func InitClientMiddleware(ctx *apigatewayex.Context) error {
if Client == nil {
fmt.Print("[Middleware] Init GISAPI Client...")
if err := InitClient(); err != nil {
fmt.Println(err)
return httpex.NewError(500, "", "Failed to init gisapi client")
}
fmt.Println("done")
}
return nil
}
// InitClientTaskMiddleware init gisapi client task middleware
func InitClientTaskMiddleware(ctx *sfnex.Context) error {
if Client == nil {
fmt.Print("[Middleware] Init GISAPI Client...")
if err := InitClient(); err != nil {
fmt.Println(err)
return errors.New("Failed to init gisapi client")
}
fmt.Println("done")
}
return nil
}
// Code generated by github.com/chouandy/goex/awsex/gen-api/main.go. DO NOT EDIT.
package gisapi
import (
"os"
)
var scheme = os.Getenv("GISAPI_SCHEME")
var endpoint = os.Getenv("GISAPI_ENDPOINT")
var apiKey = os.Getenv("GISAPI_API_KEY")
// SetScheme set scheme
func SetScheme(s string) {
scheme = s
}
// SetEndpoint set endpoint
func SetEndpoint(s string) {
endpoint = s
}
// SetAPIKey set api key
func SetAPIKey(s string) {
apiKey = s
}
// Code generated by github.com/chouandy/goex/awsex/gen-api/main.go. DO NOT EDIT.
package gisapi
import (
"github.com/aws/aws-sdk-go-v2/aws"
)
func init() {
initClient = func(s *GISAPI) {
// Set default request headers
s.Handlers.Build.PushBack(func(r *aws.Request) {
r.HTTPRequest.Header.Add("Accept", "application/json")
r.HTTPRequest.Header.Add("X-Api-Key", apiKey)
})
// Set url
var url string
if len(scheme) > 0 {
url = scheme + "://" + endpoint
} else {
url = "https://" + endpoint
}
s.Client.Config.EndpointResolver = aws.ResolveWithEndpointURL(url)
}
}
// Code generated by github.com/chouandy/goex/awsex/gen-api/main.go. DO NOT EDIT.
package gisapi
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/aws-sdk-go-v2/private/protocol/restjson"
)
// GISAPI provides the API operation methods for making requests to
// GISAPI. See this package's package overview docs
// for details on the service.
//
// GISAPI methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type GISAPI struct {
*aws.Client
}
// Used for custom client initialization logic
var initClient func(*GISAPI)
// Used for custom request initialization logic
var initRequest func(*GISAPI, *aws.Request)
// Service information constants
const (
ServiceName = "execute-api" // Service endpoint prefix API calls made to.
EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
)
// New creates a new instance of the GISAPI client with a config.
//
// Example:
// // Create a GISAPI client from just a config.
// svc := gisapi.New(myConfig)
func New(config aws.Config) *GISAPI {
var signingName string
signingRegion := config.Region
svc := &GISAPI{
Client: aws.NewClient(
config,
aws.Metadata{
ServiceName: ServiceName,
SigningName: signingName,
SigningRegion: signingRegion,
APIVersion: "2015-07-09",
},
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
svc.Handlers.Build.PushBackNamed(restjson.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(restjson.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(restjson.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(restjson.UnmarshalErrorHandler)
// Run custom client initialization if present
if initClient != nil {
initClient(svc)
}
return svc
}
// newRequest creates a new request for a GISAPI operation and runs any
// custom request initialization.
func (c *GISAPI) newRequest(op *aws.Operation, params, data interface{}) *aws.Request {
req := c.NewRequest(op, params, data)
// Run custom request initialization if present
if initRequest != nil {
initRequest(c, req)
}
return req
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment