本文整理汇总了Golang中github.com/devicehive/devicehive-go/devicehive/log.Warnf函数的典型用法代码示例。如果您正苦于以下问题:Golang Warnf函数的具体用法?Golang Warnf怎么用?Golang Warnf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warnf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processPollNotification
// Process PollNotification task
func (service *Service) processPollNotification(task Task) (notifications []core.Notification, err error) {
// check task error first
if task.err != nil {
err = task.err
return
}
// check status code
if task.response.StatusCode != http.StatusOK {
log.Warnf("REST: unexpected /notification/poll status %s",
task.response.Status)
err = fmt.Errorf("unexpected status: %s",
task.response.Status)
return
}
// unmarshal
err = json.Unmarshal(task.body, ¬ifications)
if err != nil {
log.Warnf("REST: failed to parse /notification/poll body (error: %s)", err)
return
}
return
}
示例2: UpdateCommand
// CommandUpdate() function updates the command.
func (service *Service) UpdateCommand(device *core.Device, command *core.Command, timeout time.Duration) (err error) {
task, err := service.prepareUpdateCommand(device, command)
if err != nil {
log.Warnf("WS: failed to prepare /command/update task (error: %s)", err)
return
}
// add to the TX pipeline
service.tx <- task
select {
case <-time.After(timeout):
log.Warnf("WS: failed to wait %s for /command/update task", timeout)
err = fmt.Errorf("timed out")
case <-task.done:
err = service.processUpdateCommand(task)
if err != nil {
log.Warnf("WS: failed to process /command/update task (error: %s)", err)
return
}
}
return
}
示例3: InsertNotification
// InsertNotification() function inserts the notification.
func (service *Service) InsertNotification(device *core.Device, notification *core.Notification, timeout time.Duration) (err error) {
task, err := service.prepareInsertNotification(device, notification)
if err != nil {
log.Warnf("WS: failed to prepare /notification/insert task (error: %s)", err)
return
}
// add to the TX pipeline
service.tx <- task
select {
case <-time.After(timeout):
log.Warnf("WS: failed to wait %s for /notification/insert task", timeout)
err = fmt.Errorf("timed out")
case <-task.done:
err = service.processInsertNotification(task, notification)
if err != nil {
log.Warnf("WS: failed to process /notification/insert task (error: %s)", err)
return
}
}
return
}
示例4: prepareInsertNotification
// Prepare InsertNotification task
func (service *Service) prepareInsertNotification(device *core.Device, notification *core.Notification) (task Task, err error) {
// create request
url := fmt.Sprintf("%s/device/%s/notification", service.baseUrl, device.Id)
// do not put some fields to the request body
notification = &core.Notification{Name: notification.Name,
Parameters: notification.Parameters}
body, err := json.Marshal(notification)
if err != nil {
log.Warnf("REST: failed to format /notification/insert request (error: %s)", err)
return
}
task.request, err = http.NewRequest("POST", url, bytes.NewBuffer(body))
if err != nil {
log.Warnf("REST: failed to create /notification/insert request (error: %s)", err)
return
}
task.request.Header.Add("Content-Type", "application/json")
// authorization
service.prepareAuthorization(task.request, device)
return
}
示例5: GetNetwork
// GetNetwork() function get the network data.
func (service *Service) GetNetwork(networkId uint64, timeout time.Duration) (network *core.Network, err error) {
log.Tracef("REST: getting network %d...", networkId)
task, err := service.prepareGetNetwork(networkId)
if err != nil {
log.Warnf("REST: failed to prepare /network/get task (error: %s)", err)
return
}
select {
case <-time.After(timeout):
log.Warnf("REST: failed to wait %s for /network/get task", timeout)
err = fmt.Errorf("timed out")
case task = <-service.doAsync(task):
network = &core.Network{Id: networkId}
err = service.processGetNetwork(task, network)
if err != nil {
log.Warnf("REST: failed to process /network/get task (error: %s)", err)
return
}
}
return
}
示例6: GetNotification
// GetNotification() function get the notification data.
func (service *Service) GetNotification(device *core.Device, notificationId uint64, timeout time.Duration) (notification *core.Notification, err error) {
log.Tracef("REST: getting notification %q/%d...", device.Id, notificationId)
task, err := service.prepareGetNotification(device, notificationId)
if err != nil {
log.Warnf("REST: failed to prepare /notification/get task (error: %s)", err)
return
}
select {
case <-time.After(timeout):
log.Warnf("REST: failed to wait %s for /notification/get task", timeout)
err = fmt.Errorf("timed out")
case task = <-service.doAsync(task):
notification = &core.Notification{Id: notificationId}
err = service.processGetNotification(task, notification)
if err != nil {
log.Warnf("REST: failed to process /notification/get task (error: %s)", err)
return
}
}
return
}
示例7: GetServerInfo
// GetServerInfo() function gets the main server's information.
func (service *Service) GetServerInfo(timeout time.Duration) (info *core.ServerInfo, err error) {
task, err := service.prepareGetServerInfo()
if err != nil {
log.Warnf("WS: failed to prepare /info task (error: %s)", err)
return
}
// add to the TX pipeline
service.tx <- task
select {
case <-time.After(timeout):
log.Warnf("WS: failed to wait %s for /info task", timeout)
err = fmt.Errorf("timed out")
case <-task.done:
info = &core.ServerInfo{}
err = service.processGetServerInfo(task, info)
if err != nil {
log.Warnf("WS: failed to process /info task (error: %s)", err)
return
}
}
return
}
示例8: UnsubscribeCommands
// UnsubscribeCommand() function updates the command.
func (service *Service) UnsubscribeCommands(device *core.Device, timeout time.Duration) (err error) {
task, err := service.prepareUnsubscribeCommand(device)
if err != nil {
log.Warnf("WS: failed to prepare /command/unsubscribe task (error: %s)", err)
return
}
service.removeCommandListener(device.Id)
// add to the TX pipeline
service.tx <- task
select {
case <-time.After(timeout):
log.Warnf("WS: failed to wait %s for /command/unsubscribe task", timeout)
err = fmt.Errorf("timed out")
case <-task.done:
err = service.processUnsubscribeCommand(task)
if err != nil {
log.Warnf("WS: failed to process /command/unsubscribe task (error: %s)", err)
return
}
}
return
}
示例9: processInsertNetwork
// Process InsertNetwork task
func (service *Service) processInsertNetwork(task Task, network *core.Network) (err error) {
// check task error first
if task.err != nil {
err = task.err
return
}
// check status code
if task.response.StatusCode < http.StatusOK ||
task.response.StatusCode > http.StatusPartialContent {
log.Warnf("REST: unexpected /network/insert status %s",
task.response.Status)
err = fmt.Errorf("unexpected status: %s",
task.response.Status)
return
}
// unmarshal
err = json.Unmarshal(task.body, network)
if err != nil {
log.Warnf("REST: failed to parse /network/insert body (error: %s)", err)
return
}
return
}
示例10: GetDevice
// GetDevice() function get the device data.
func (service *Service) GetDevice(deviceId, deviceKey string, timeout time.Duration) (device *core.Device, err error) {
log.Tracef("REST: getting device %q...", deviceId)
task, err := service.prepareGetDevice(deviceId, deviceKey)
if err != nil {
log.Warnf("REST: failed to prepare /device/get task (error: %s)", err)
return
}
select {
case <-time.After(timeout):
log.Warnf("REST: failed to wait %s for /device/get task", timeout)
err = fmt.Errorf("timed out")
case task = <-service.doAsync(task):
device = &core.Device{Id: deviceId, Key: deviceKey}
err = service.processGetDevice(task, device)
if err != nil {
log.Warnf("REST: failed to process /device/get task (error: %s)", err)
return
}
}
return
}
示例11: RegisterDevice
// RegisterDevice() function registers the device.
func (service *Service) RegisterDevice(device *core.Device, timeout time.Duration) (err error) {
task, err := service.prepareRegisterDevice(device)
if err != nil {
log.Warnf("WS: failed to prepare /device/register task (error: %s)", err)
return
}
// add to the TX pipeline
service.tx <- task
select {
case <-time.After(timeout):
log.Warnf("WS: failed to wait %s for /device/register task", timeout)
err = fmt.Errorf("timed out")
case <-task.done:
err = service.processRegisterDevice(task)
if err != nil {
log.Warnf("WS: failed to process /device/register task (error: %s)", err)
return
}
}
return
}
示例12: processGetCommand
// Process GetCommand task
func (service *Service) processGetCommand(task Task, command *core.Command) (err error) {
// check task error first
if task.err != nil {
err = task.err
return
}
// check status code
if task.response.StatusCode != http.StatusOK {
log.Warnf("REST: unexpected /command/get status %s",
task.response.Status)
err = fmt.Errorf("unexpected status: %s",
task.response.Status)
return
}
// unmarshal
err = json.Unmarshal(task.body, command)
if err != nil {
log.Warnf("REST: failed to parse /command/get body (error: %s)", err)
return
}
return
}
示例13: processGetDeviceList
// Process GetDeviceList task
func (service *Service) processGetDeviceList(task Task) (devices []core.Device, err error) {
// check task error first
if task.err != nil {
err = task.err
return
}
// check status code
if task.response.StatusCode != http.StatusOK {
log.Warnf("REST: unexpected /device/list status %s",
task.response.Status)
err = fmt.Errorf("unexpected status: %s",
task.response.Status)
return
}
// unmarshal
err = json.Unmarshal(task.body, &devices)
if err != nil {
log.Warnf("REST: failed to parse /device/list body (error: %s)", err)
return
}
return
}
示例14: prepareInsertCommand
// Prepare InsertCommand task
func (service *Service) prepareInsertCommand(device *core.Device, command *core.Command) (task Task, err error) {
// create request
url := fmt.Sprintf("%s/device/%s/command", service.baseUrl, device.Id)
// do not put some fields to the request body
command = &core.Command{Name: command.Name,
Parameters: command.Parameters,
Lifetime: command.Lifetime}
body, err := json.Marshal(command)
if err != nil {
log.Warnf("REST: failed to format /command/insert request (error: %s)", err)
return
}
task.request, err = http.NewRequest("POST", url, bytes.NewBuffer(body))
if err != nil {
log.Warnf("REST: failed to create /command/insert request (error: %s)", err)
return
}
task.request.Header.Add("Content-Type", "application/json")
// authorization
service.prepareAuthorization(task.request, device)
return
}
示例15: GetCommand
// GetCommand() function get the command data.
func (service *Service) GetCommand(device *core.Device, commandId uint64, timeout time.Duration) (command *core.Command, err error) {
log.Debugf("REST: getting command %q/%d...", device.Id, commandId)
task, err := service.prepareGetCommand(device, commandId)
if err != nil {
log.Warnf("REST: failed to prepare /command/get task (error: %s)", err)
return
}
select {
case <-time.After(timeout):
log.Warnf("REST: failed to wait %s for /command/get task", timeout)
err = fmt.Errorf("timed out")
case task = <-service.doAsync(task):
command = &core.Command{Id: commandId}
err = service.processGetCommand(task, command)
if err != nil {
log.Warnf("REST: failed to process /command/get task (error: %s)", err)
return
}
}
return
}