1 Star 0 Fork 0

南京未来物联科技有限公司 / fn-onvif

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sdk.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
lan_xin2578 提交于 2023-06-25 19:59 . first commit
package sdk
import (
"context"
"encoding/xml"
"io/ioutil"
"net/http"
"os"
"time"
"github.com/juju/errors"
"github.com/rs/zerolog"
)
var (
// LoggerContext is the builder of a zerolog.Logger that is exposed to the application so that
// options at the CLI might alter the formatting and the output of the logs.
LoggerContext = zerolog.
New(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}).
With().Timestamp()
// Logger is a zerolog logger, that can be safely used from any part of the application.
// It gathers the format and the output.
Logger = LoggerContext.Logger()
)
func ReadAndParse(ctx context.Context, httpReply *http.Response, reply interface{}, tag string) error {
Logger.Debug().
Str("msg", httpReply.Status).
Int("status", httpReply.StatusCode).
Str("action", tag).
Msg("RPC")
// TODO(jfsmig): extract the deadline from ctx.Deadline() and apply it on the reply reading
b, err := ioutil.ReadAll(httpReply.Body)
if err != nil {
return errors.Annotate(err, "read")
}
httpReply.Body.Close()
err = xml.Unmarshal(b, reply)
return errors.Annotate(err, "decode")
}
Go
1
https://gitee.com/fnaiot/fn-onvif.git
git@gitee.com:fnaiot/fn-onvif.git
fnaiot
fn-onvif
fn-onvif
v1.0.0

搜索帮助