// GatewayBot returns the websocket Gateway address and the recommended number of shards
512204
func (s *Session) GatewayBot() (st *GatewayBotResponse, err error) {

	response, err := s.RequestWithBucketID("GET", EndpointGatewayBot, nil, EndpointGatewayBot)
	if err != nil {
		return
	}

	err = unmarshal(response, &st)
	if err != nil {
		return
	}

	// Ensure the gateway always has a trailing slash.
	// MacOS will fail to connect if we add query params without a trailing slash on the base domain.
	if !strings.HasSuffix(st.URL, "/") {
		st.URL += "/"
	}

	return
}
972436
func GetGatewayID(v GatewayIDGetter) lorawan.EUI64 {
	var gatewayID lorawan.EUI64
	copy(gatewayID[:], v.GetGatewayId())
	return gatewayID
}
1089839
func (de *DefaultExtender) RequestRobots(ctx *URLContext, robotAgent string) (data []byte, doRequest bool) {
	return nil, true
}
396896
func (a *Account) GatewayCollaborators(gwID string) ([]Collaborator, error) {
	collaborators := make([]Collaborator, 0)
	err := a.get(a.auth.WithScope(scope.Gateway(gwID)), fmt.Sprintf("/api/v2/gateways/%s/collaborators", gwID), &collaborators)
	if err != nil {
		return nil, err
	}

	return collaborators, nil
}
1210613
func processBots(c context.Context, descriptors []model.PoolDescriptor) error {
	return parallel.WorkPool(8, func(ch chan<- func() error) {
		for _, desc := range descriptors {
			desc := desc
			ch <- func() error {
				return processBot(c, desc)
			}
		}
	})
}
1165891
func (s *DescribeWorkingStorageInput) SetGatewayARN(v string) *DescribeWorkingStorageInput {
	s.GatewayARN = &v
	return s
}
1350013
func (r Hardware_Router) GetMonitoringRobot() (resp datatypes.Monitoring_Robot, err error) {
	err = r.Session.DoRequest("SoftLayer_Hardware_Router", "getMonitoringRobot", nil, &r.Options, &resp)
	return
}
561645
func processBot(c context.Context, desc model.PoolDescriptor) error {
	t, err := auth.GetRPCTransport(c, auth.AsSelf)
	if err != nil {
		return err
	}
	sc, err := swarmingAPI.New(&http.Client{Transport: t})
	if err != nil {
		return err
	}
	sc.BasePath = fmt.Sprintf("https://%s/_ah/api/swarming/v1/", desc.Host())

	var bots []model.Bot
	bl := sc.Bots.List().Dimensions(desc.Dimensions().Format()...)
	// Keep fetching until the cursor is empty.
	for {
		botList, err := bl.Do()
		if err != nil {
			return err
		}
		for _, botInfo := range botList.Items {
			// Ignore deleted bots.
			if botInfo.Deleted {
				continue
			}
			bot, err := parseBot(c, desc.Host(), botInfo)
			if err != nil {
				return err
			}
			bots = append(bots, *bot)
		}

		if botList.Cursor == "" {
			break
		}
		bl = bl.Cursor(botList.Cursor)
	}
	// If there are too many bots, then it won't fit in datastore.
	// Only store a subset of the bots.
	// TODO(hinoka): This is inaccurate, but will only affect few builders.
	// Instead of chopping this list off, just store the statistics.
	if len(bots) > 1000 {
		bots = bots[:1000]
	}
	// This is a large RPC, don't try to batch it.
	return datastore.Put(c, &model.BotPool{
		PoolID:     desc.PoolID(),
		Descriptor: desc,
		Bots:       bots,
		LastUpdate: clock.Now(c),
	})
}
426725
func (s *DescribeBandwidthRateLimitOutput) SetGatewayARN(v string) *DescribeBandwidthRateLimitOutput {
	s.GatewayARN = &v
	return s
}
798213
func hexGatewayToAddr(gateway []rune) (string, error) {
	// gateway address is encoded in reverse order in hex
	if len(gateway) != 8 {
		return "", errors.New("invalid gateway length")
	}

	var octets [4]uint8
	for i, hexOctet := range [4]string{
		string(gateway[6:8]), // first octet of IP Address
		string(gateway[4:6]), // second octet
		string(gateway[2:4]), // third octet
		string(gateway[0:2]), // last octet
	} {
		octet, err := strconv.ParseUint(hexOctet, 16, 8)
		if err != nil {
			return "", err
		}

		octets[i] = uint8(octet)
	}

	return fmt.Sprintf("%v.%v.%v.%v", octets[0], octets[1], octets[2], octets[3]), nil
}
756373
func (a *API) robotConnections(res http.ResponseWriter, req *http.Request) {
	jsonConnections := []*gobot.JSONConnection{}
	if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil {
		robot.Connections().Each(func(c gobot.Connection) {
			jsonConnections = append(jsonConnections, gobot.NewJSONConnection(c))
		})
		a.writeJSON(map[string]interface{}{"connections": jsonConnections}, res)
	} else {
		a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res)
	}

}
588318
func (s *UpdateBandwidthRateLimitOutput) SetGatewayARN(v string) *UpdateBandwidthRateLimitOutput {
	s.GatewayARN = &v
	return s
}
64023
func (a *Account) FindGateway(gatewayID string) (gateway Gateway, err error) {
	var res gatewayRes
	err = a.get(a.auth.WithScope(scope.Gateway(gatewayID)), fmt.Sprintf("/api/v2/gateways/%s", gatewayID), &res)
	if err != nil {
		return gateway, err
	}
	return res.ToGateway(), err
}
1237597
func GetGatewayCache(p *redis.Pool, gatewayID lorawan.EUI64) (Gateway, error) {
	var gw Gateway
	key := fmt.Sprintf(gatewayKeyTempl, gatewayID)

	c := p.Get()
	defer c.Close()

	val, err := redis.Bytes(c.Do("GET", key))
	if err != nil {
		if err == redis.ErrNil {
			return gw, ErrDoesNotExist
		}
		return gw, errors.Wrap(err, "get error")
	}

	err = gob.NewDecoder(bytes.NewReader(val)).Decode(&gw)
	if err != nil {
		return gw, errors.Wrap(err, "gob decode error")
	}

	return gw, nil
}
643116
func (s *VolumeInfo) SetGatewayARN(v string) *VolumeInfo {
	s.GatewayARN = &v
	return s
}
790407
func (s *FileShareInfo) SetGatewayARN(v string) *FileShareInfo {
	s.GatewayARN = &v
	return s
}
119909
func (t *Template) GetAWSRoboMakerRobotApplicationWithName(name string) (*resources.AWSRoboMakerRobotApplication, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSRoboMakerRobotApplication:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSRoboMakerRobotApplication not found", name)
}