本文整理汇总了Golang中github.com/devicehive/devicehive-go/devicehive/log.Warnf函数的典型用法代码示例。如果您正苦于以下问题:Golang Warnf函数的具体用法?Golang Warnf怎么用?Golang Warnf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warnf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:notification_poll.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:command_update.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:notification_insert.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:27,代码来源:notification_insert.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:network_get.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:notification_get.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:27,代码来源:server_info.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:28,代码来源:command_unsubscribe.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:27,代码来源:network_insert.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:device_get.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:device_register.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:command_get.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:device_list.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:28,代码来源:command_insert.go
示例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
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:command_get.go
示例16: doAsync
// Do a request/task asynchronously
func (service *Service) doAsync(task Task) <-chan Task {
ch := make(chan Task, 1)
go func() {
defer func() { ch <- task }()
log.Tracef("REST: sending: %+v", task.request)
task.response, task.err = service.client.Do(task.request)
if task.err != nil {
log.Warnf("REST: failed to do %s %s request (error: %s)",
task.request.Method, task.request.URL, task.err)
return
}
log.Tracef("REST: got %s %s response: %+v",
task.request.Method, task.request.URL, task.response)
// read body
defer task.response.Body.Close()
task.body, task.err = ioutil.ReadAll(task.response.Body)
if task.err != nil {
log.Warnf("REST: failed to read %s %s response body (error: %s)",
task.request.Method, task.request.URL, task.err)
return
}
log.Debugf("REST: got %s %s body: %s",
task.request.Method, task.request.URL, string(task.body))
}()
return ch
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:32,代码来源:service.go
示例17: doTX
// TX thread
func (service *Service) doTX() {
for {
select {
case task, ok := <-service.tx:
if !ok || task == nil {
log.Infof("WS: TX thread stopped")
service.conn.Close() // TODO: send Close frame?
return
}
body, err := task.Format()
if err != nil {
log.Warnf("WS: failed to format message (error: %s)", err)
continue // TODO: return?
}
log.Tracef("WS: sending message: %s", string(body))
err = service.conn.WriteMessage(websocket.TextMessage, body)
if err != nil {
log.Warnf("WS: failed to send message (error: %s)", err)
continue // TODO: return?
}
// case <-service.pingTimer.C:
// if err := c.write(websocket.PingMessage, []byte{}); err != nil {
// log.Warnf("WS: could not write ping message (error: %s)", err)
// return
// }
}
}
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:32,代码来源:service.go
示例18: SubscribeCommands
// SubscribeCommand() function updates the command.
func (service *Service) SubscribeCommands(device *core.Device, timestamp string, timeout time.Duration) (listener *core.CommandListener, err error) {
task, err := service.prepareSubscribeCommand(device, timestamp)
if err != nil {
log.Warnf("WS: failed to prepare /command/subscribe 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/subscribe task", timeout)
err = fmt.Errorf("timed out")
case <-task.done:
err = service.processSubscribeCommand(task)
if err != nil {
log.Warnf("WS: failed to process /command/subscribe task (error: %s)", err)
return
}
// done, create listener
listener = core.NewCommandListener()
service.insertCommandListener(device.Id, listener)
}
return
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:30,代码来源:command_subscribe.go
示例19: mainLoop
// main loop
func mainLoop(bus *dbus.Conn, service devicehive.Service, config conf.Conf) {
// getting server info
info, err := service.GetServerInfo(waitTimeout)
if err != nil {
log.Warnf("Cannot get service info (error: %s)", err)
return
}
// registering device
device := devicehive.NewDevice(config.DeviceID, config.DeviceName,
devicehive.NewDeviceClass("go-gateway-class", "0.1"))
device.Key = config.DeviceKey
if len(config.NetworkName) != 0 || len(config.NetworkKey) != 0 {
device.Network = devicehive.NewNetwork(config.NetworkName, config.NetworkKey)
device.Network.Description = config.NetworkDesc
}
err = service.RegisterDevice(device, waitTimeout)
if err != nil {
log.Warnf("Cannot register device (error: %s)", err)
return
}
// start polling commands
listener, err := service.SubscribeCommands(device, info.Timestamp, waitTimeout)
if err != nil {
log.Warnf("Cannot subscribe commands (error: %s)")
return
}
wrapper := DBusWrapper{service: service, device: device}
exportDBusObject(bus, &wrapper)
for {
select {
case cmd := <-listener.C:
params := ""
if cmd.Parameters != nil {
buf, err := json.Marshal(cmd.Parameters)
if err != nil {
log.Warnf("Cannot generate JSON from parameters of command %+v (error: %s)", cmd, err)
continue
}
params = string(buf)
}
log.Infof("COMMAND %s -> %s(%v)", config.URL, cmd.Name, params)
bus.Emit(ComDevicehiveCloudPath, ComDevicehiveCloudIface+".CommandReceived", cmd.Id, cmd.Name, params)
}
//time.Sleep(5 * time.Second)
}
}
开发者ID:ndjido,项目名称:IoT-framework,代码行数:52,代码来源:main-loop.go
示例20: prepareGetDeviceList
// Prepare GetDeviceList task
func (service *Service) prepareGetDeviceList(take, skip int) (task Task, err error) {
// create request
query := url.Values{}
if take > 0 {
query.Set("take", fmt.Sprintf("%d", take))
}
if skip > 0 {
query.Set("skip", fmt.Sprintf("%d", skip))
}
url := fmt.Sprintf("%s/device", service.baseUrl)
if len(query) != 0 {
url += "?" + query.Encode()
}
task.request, err = http.NewRequest("GET", url, nil)
if err != nil {
log.Warnf("REST: failed to create /device/list request (error: %s)", err)
return
}
// authorization
service.prepareAuthorization(task.request, nil)
return
}
开发者ID:devicehive,项目名称:devicehive-go,代码行数:26,代码来源:device_list.go
注:本文中的github.com/devicehive/devicehive-go/devicehive/log.Warnf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论