本文整理汇总了Golang中github.com/brutella/log.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Printf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewDevice
func NewDevice(device common.Device) {
if light, ok := device.(common.Light); ok {
hkLight := GetHKLight(light)
hkLight.sub, _ = light.NewSubscription()
for {
event := <-hkLight.sub.Events()
switch event.(type) {
case common.EventUpdateLabel:
log.Printf("[INFO] Updated Label for %s to %s", hkLight.accessory.Name(), event.(common.EventUpdateLabel).Label)
// TODO Add support for label changes to HomeControl
log.Printf("[INFO] Unsupported by HomeControl")
case common.EventUpdatePower:
log.Printf("[INFO] Updated Power for %s", hkLight.accessory.Name())
hkLight.light.SetOn(event.(common.EventUpdatePower).Power)
case common.EventUpdateColor:
log.Printf("[INFO] Updated Color for %s", hkLight.accessory.Name())
hue, saturation, brightness := ConvertLIFXColor(event.(common.EventUpdateColor).Color)
hkLight.light.SetHue(hue)
hkLight.light.SetSaturation(saturation)
hkLight.light.SetBrightness(int(brightness))
default:
log.Printf("[INFO] Unknown Device Event: %T", event)
}
}
} else {
log.Println("[INFO] Unsupported Device")
}
}
开发者ID:Pmaene,项目名称:hklifx,代码行数:32,代码来源:hklifxd.go
示例2: ServeHTTP
func (handler *Characteristics) ServeHTTP(response http.ResponseWriter, request *http.Request) {
var res io.Reader
var err error
handler.mutex.Lock()
switch request.Method {
case netio.MethodGET:
log.Printf("[VERB] %v GET /characteristics", request.RemoteAddr)
request.ParseForm()
res, err = handler.controller.HandleGetCharacteristics(request.Form)
case netio.MethodPUT:
log.Printf("[VERB] %v PUT /characteristics", request.RemoteAddr)
session := handler.context.GetSessionForRequest(request)
conn := session.Connection()
err = handler.controller.HandleUpdateCharacteristics(request.Body, conn)
default:
log.Println("[WARN] Cannot handle HTTP method", request.Method)
}
handler.mutex.Unlock()
if err != nil {
log.Println("[ERRO]", err)
response.WriteHeader(http.StatusInternalServerError)
} else {
if res != nil {
response.Header().Set("Content-Type", netio.HTTPContentTypeHAPJson)
wr := netio.NewChunkedWriter(response, 2048)
b, _ := ioutil.ReadAll(res)
wr.Write(b)
} else {
response.WriteHeader(http.StatusNoContent)
}
}
}
开发者ID:smitterson,项目名称:hc,代码行数:34,代码来源:characteristics.go
示例3: Handle
// Handles event which are sent when pairing with a device is added or removed
func (t *ipTransport) Handle(ev interface{}) {
switch ev.(type) {
case event.DevicePaired:
log.Printf("[INFO] Event: paired with device")
t.updateMDNSReachability()
case event.DeviceUnpaired:
log.Printf("[INFO] Event: unpaired with device")
t.updateMDNSReachability()
default:
break
}
}
开发者ID:smitterson,项目名称:hc,代码行数:13,代码来源:ip_transport.go
示例4: main
func main() {
log.Println("[ERRO] Just an error")
log.Printf("[ERRO] Just an error %d", 1)
log.Println("[WARN] Just a warning")
log.Printf("[WARN] Just a warning %d", 1)
log.Println("[INFO] Just an info")
log.Printf("[INFO] Just an info %d", 1)
log.Println("[VERB] Just an info")
log.Printf("[VERB] Just an info %d", 1)
log.Error = false
log.Warn = false
log.Info = false
log.Verbose = false
log.Println("MUST be displayed")
log.Println("[ERRO] MUST NOT be displayed")
log.Printf("[ERRO] MUST NOT be displayed %d", 1)
log.Println("[WARN] MUST NOT be displayed")
log.Printf("[WARN] MUST NOT be displayed %d", 1)
log.Println("[INFO] MUST NOT be displayed")
log.Printf("[INFO] MUST NOT be displayed %d", 1)
log.Println("[VERB] MUST NOT be displayed")
log.Printf("[VERB] MUST NOT be displayed %d", 1)
}
开发者ID:tjbx,项目名称:X10Bridge,代码行数:25,代码来源:example.go
示例5: HandleUpdateCharacteristics
// HandleUpdateCharacteristics handles an update characteristic request. The bytes must represent
// a data.Characteristics json.
func (ctr *CharacteristicController) HandleUpdateCharacteristics(r io.Reader, conn net.Conn) error {
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
var chars data.Characteristics
err = json.Unmarshal(b, &chars)
if err != nil {
return err
}
log.Println("[VERB]", string(b))
for _, c := range chars.Characteristics {
characteristic := ctr.GetCharacteristic(c.AccessoryID, c.ID)
if characteristic == nil {
log.Printf("[ERRO] Could not find characteristic with aid %d and iid %d\n", c.AccessoryID, c.ID)
continue
}
if c.Value != nil {
characteristic.SetValueFromConnection(c.Value, conn)
}
if events, ok := c.Events.(bool); ok == true {
characteristic.SetEventsEnabled(events)
}
}
return err
}
开发者ID:smitterson,项目名称:hc,代码行数:34,代码来源:characteristic_controller.go
示例6: ServeHTTP
func (handler *PairVerify) ServeHTTP(response http.ResponseWriter, request *http.Request) {
log.Printf("[VERB] %v POST /pair-verify", request.RemoteAddr)
response.Header().Set("Content-Type", netio.HTTPContentTypePairingTLV8)
key := handler.context.GetConnectionKey(request)
session := handler.context.Get(key).(netio.Session)
controller := session.PairVerifyHandler()
if controller == nil {
log.Println("[VERB] Create new pair verify controller")
controller = pair.NewVerifyServerController(handler.database, handler.context)
session.SetPairVerifyHandler(controller)
}
res, err := pair.HandleReaderForHandler(request.Body, controller)
if err != nil {
log.Println(err)
response.WriteHeader(http.StatusInternalServerError)
} else {
io.Copy(response, res)
// Setup secure session
if controller.KeyVerified() == true {
// Verification is done
// Switch to secure session
secureSession, err := crypto.NewSecureSessionFromSharedKey(controller.SharedKey())
if err != nil {
log.Println("[ERRO] Could not setup secure session.", err)
} else {
log.Println("[VERB] Setup secure session")
}
session.SetCryptographer(secureSession)
}
}
}
开发者ID:tjbx,项目名称:X10Bridge,代码行数:34,代码来源:pair-verify.go
示例7: ServeHTTP
func (handler *PairSetup) ServeHTTP(response http.ResponseWriter, request *http.Request) {
log.Printf("[VERB] %v POST /pair-setup", request.RemoteAddr)
response.Header().Set("Content-Type", netio.HTTPContentTypePairingTLV8)
key := handler.context.GetConnectionKey(request)
session := handler.context.Get(key).(netio.Session)
controller := session.PairSetupHandler()
if controller == nil {
log.Println("[VERB] Create new pair setup controller")
var err error
controller, err = pair.NewSetupServerController(handler.device, handler.database)
if err != nil {
log.Println(err)
}
session.SetPairSetupHandler(controller)
}
res, err := pair.HandleReaderForHandler(request.Body, controller)
if err != nil {
log.Println("[ERRO]", err)
response.WriteHeader(http.StatusInternalServerError)
} else {
io.Copy(response, res)
}
}
开发者ID:tjbx,项目名称:X10Bridge,代码行数:27,代码来源:pair-setup.go
示例8: ServeHTTP
func (endpoint *Pairing) ServeHTTP(response http.ResponseWriter, request *http.Request) {
log.Printf("[VERB] %v POST /pairings", request.RemoteAddr)
response.Header().Set("Content-Type", netio.HTTPContentTypePairingTLV8)
var err error
var in util.Container
var out util.Container
if in, err = util.NewTLV8ContainerFromReader(request.Body); err == nil {
out, err = endpoint.controller.Handle(in)
}
if err != nil {
log.Println(err)
response.WriteHeader(http.StatusInternalServerError)
} else {
io.Copy(response, out.BytesBuffer())
// Send events based on pairing method type
b := in.GetByte(pair.TagPairingMethod)
switch pair.PairMethodType(b) {
case pair.PairingMethodDelete: // pairing removed
endpoint.emitter.Emit(event.DeviceUnpaired{})
case pair.PairingMethodAdd: // pairing added
endpoint.emitter.Emit(event.DevicePaired{})
}
}
}
开发者ID:smitterson,项目名称:hc,代码行数:30,代码来源:pairings.go
示例9: setupHive
func setupHive() {
// Connect to Hive
var err error
hiveHome, err = hive.Connect(hive.Config{
Username: username,
Password: password,
RefreshInterval: 30 * time.Second,
})
if err != nil {
log.Fatal(err)
return
}
hiveHome.HandleStateChange(func(state *hive.State) {
accessoryUpdate.Lock()
defer accessoryUpdate.Unlock()
log.Printf("[VERB] Syncing status with HomeKit\n")
hotWaterSwitch.Switch.On.SetValue(state.HotWater)
heatingBoostSwitch.Switch.On.SetValue(state.HeatingBoosted)
thermostat.Thermostat.CurrentTemperature.SetValue(state.CurrentTemp)
thermostat.Thermostat.TargetTemperature.SetValue(state.TargetTemp)
thermostat.Thermostat.CurrentHeatingCoolingState.SetValue(modeForHiveMode(state.CurrentHeatingMode))
thermostat.Thermostat.TargetHeatingCoolingState.SetValue(modeForHiveMode(state.TargetHeatingMode))
})
}
开发者ID:njpatel,项目名称:hivekit,代码行数:30,代码来源:main.go
示例10: Handle
// Handle processes a container to pair with a new client without going through the pairing process.
func (c *PairingController) Handle(cont util.Container) (util.Container, error) {
method := pairMethodType(cont.GetByte(TagPairingMethod))
username := cont.GetString(TagUsername)
publicKey := cont.GetBytes(TagPublicKey)
log.Println("[VERB] -> Method:", method)
log.Println("[VERB] -> Username:", username)
log.Println("[VERB] -> LTPK:", publicKey)
entity := db.NewEntity(username, publicKey, nil)
switch method {
case PairingMethodDelete:
log.Printf("[INFO] Remove LTPK for client '%s'\n", username)
c.database.DeleteEntity(entity)
case PairingMethodAdd:
err := c.database.SaveEntity(entity)
if err != nil {
log.Println("[ERRO]", err)
return nil, err
}
default:
return nil, fmt.Errorf("Invalid pairing method type %v", method)
}
out := util.NewTLV8Container()
out.SetByte(TagSequence, 0x2)
return out, nil
}
开发者ID:tjbx,项目名称:X10Bridge,代码行数:31,代码来源:pairing_controller.go
示例11: Connect
func Connect() {
var wg sync.WaitGroup
authenticate()
urlString := fmt.Sprintf("http://%s/sensors", viper.GetString("Host"))
req, _ := newRequest("GET", urlString, nil)
res, _ := client.Do(req)
defer res.Body.Close()
jsonBytes, _ := ioutil.ReadAll(res.Body)
jsonParsed, _ := gabs.ParseJSON(jsonBytes)
children, _ := jsonParsed.Search("sensors").Children()
wg.Add(len(children))
for _, child := range children {
port := uint8(child.Path("port").Data().(float64))
output := child.Path("output").Data().(float64) != 0
log.Printf("[INFO] Discovered Sensor %d", port)
sensor := &MPSensor{port, output}
go NewSensor(wg, sensor)
}
wg.Wait()
}
开发者ID:Pmaene,项目名称:hkmpower,代码行数:27,代码来源:hkmpowerd.go
示例12: NewSensor
func NewSensor(wg sync.WaitGroup, sensor *MPSensor) {
defer wg.Done()
hkSwitch := GetHKSwitch(sensor)
hkSwitch.ticker = time.NewTicker(30 * time.Second)
for {
<-hkSwitch.ticker.C
log.Printf("[INFO] Updating %s", hkSwitch.accessory.Info.Name.GetValue())
urlString := fmt.Sprintf("http://%s/sensors/%d", viper.GetString("Host"), hkSwitch.sensor.port)
req, _ := newRequest("GET", urlString, nil)
res, _ := client.Do(req)
defer res.Body.Close()
jsonBytes, _ := ioutil.ReadAll(res.Body)
jsonParsed, _ := gabs.ParseJSON(jsonBytes)
output := jsonParsed.Path("sensors").Index(0).Path("output").Data().(float64) != 0
hkSwitch.sensor.output = output
hkSwitch.accessory.Switch.On.SetValue(output)
}
}
开发者ID:Pmaene,项目名称:hkmpower,代码行数:25,代码来源:hkmpowerd.go
示例13: getStatus
func (h *Hive) getStatus(force bool) {
log.Printf("[VERB] Refreshing Hive status")
h.refreshing.Lock()
defer h.refreshing.Unlock()
now := time.Now().Unix()
if force == false && h.lastRefresh > now-avoidRetrySeconds {
return
}
res, err := h.getHTTP(h.baseURL + "/omnia/nodes")
if err != nil {
log.Printf("[WARN] Unable to get nodes info: %s", err)
return
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
var reply nodesReply
err = decoder.Decode(&reply)
if err != nil {
log.Printf("[WARN] Unable to get nodes info: %s", err)
return
}
state := newStateFromNodes(reply.Nodes)
if err != nil {
log.Printf("[WARN] Unable to extract state from reply: %s", err)
return
}
h.lastState = *state
if h.stateChangeHandler != nil {
go h.stateChangeHandler(state)
}
h.lastRefresh = now
}
开发者ID:njpatel,项目名称:hivekit,代码行数:39,代码来源:hive.go
示例14: ServeHTTP
func (handler *Pairing) ServeHTTP(response http.ResponseWriter, request *http.Request) {
log.Printf("[VERB] %v POST /pairings", request.RemoteAddr)
response.Header().Set("Content-Type", netio.HTTPContentTypePairingTLV8)
res, err := pair.HandleReaderForHandler(request.Body, handler.controller)
if err != nil {
log.Println(err)
response.WriteHeader(http.StatusInternalServerError)
} else {
io.Copy(response, res)
}
}
开发者ID:tjbx,项目名称:X10Bridge,代码行数:13,代码来源:pairings.go
示例15: GetHKSwitch
func GetHKSwitch(sensor *MPSensor) *HKSwitch {
hkSwitch, found := switches[sensor.port]
if found {
return hkSwitch
}
label := fmt.Sprintf("mPower Port %d", sensor.port)
log.Printf("[INFO] Creating New HKSwitch for %s", label)
info := accessory.Info{
Name: label,
Manufacturer: "Ubiquiti Networks",
}
acc := accessory.NewSwitch(info)
acc.Switch.On.SetValue(sensor.output)
config := hc.Config{Pin: pin}
transport, err := hc.NewIPTransport(config, acc.Accessory)
if err != nil {
log.Fatal(err)
}
go func() {
transport.Start()
}()
hkSwitch = &HKSwitch{acc, sensor, nil, transport}
switches[sensor.port] = hkSwitch
acc.OnIdentify(func() {
timeout := 1 * time.Second
for i := 0; i < 4; i++ {
ToggleSensor(sensor)
time.Sleep(timeout)
}
})
acc.Switch.On.OnValueRemoteUpdate(func(on bool) {
SetOutput(sensor, on)
})
return hkSwitch
}
开发者ID:Pmaene,项目名称:hkmpower,代码行数:45,代码来源:hkmpowerd.go
示例16: ServeHTTP
func (endpoint *PairVerify) ServeHTTP(response http.ResponseWriter, request *http.Request) {
log.Printf("[VERB] %v POST /pair-verify", request.RemoteAddr)
response.Header().Set("Content-Type", netio.HTTPContentTypePairingTLV8)
key := endpoint.context.GetConnectionKey(request)
session := endpoint.context.Get(key).(netio.Session)
ctlr := session.PairVerifyHandler()
if ctlr == nil {
log.Println("[VERB] Create new pair verify controller")
ctlr = pair.NewVerifyServerController(endpoint.database, endpoint.context)
session.SetPairVerifyHandler(ctlr)
}
var err error
var in util.Container
var out util.Container
var secSession crypto.Cryptographer
if in, err = util.NewTLV8ContainerFromReader(request.Body); err == nil {
out, err = ctlr.Handle(in)
}
if err != nil {
log.Println(err)
response.WriteHeader(http.StatusInternalServerError)
} else {
io.Copy(response, out.BytesBuffer())
// When key verification is done, switch to a secure session
// based on the negotiated shared session key
b := out.GetByte(pair.TagSequence)
switch pair.VerifyStepType(b) {
case pair.VerifyStepFinishResponse:
if secSession, err = crypto.NewSecureSessionFromSharedKey(ctlr.SharedKey()); err == nil {
log.Println("[VERB] Setup secure session")
session.SetCryptographer(secSession)
} else {
log.Println("[ERRO] Could not setup secure session.", err)
}
}
}
}
开发者ID:smitterson,项目名称:hc,代码行数:42,代码来源:pair-verify.go
示例17: notifyListener
func (t *ipTransport) notifyListener(a *accessory.Accessory, c *characteristic.Characteristic, except net.Conn) {
conns := t.context.ActiveConnections()
for _, conn := range conns {
if conn == except {
continue
}
resp, err := event.New(a, c)
if err != nil {
log.Fatal(err)
}
// Write response into buffer to replace HTTP protocol
// specifier with EVENT as required by HAP
var buffer = new(bytes.Buffer)
resp.Write(buffer)
bytes, err := ioutil.ReadAll(buffer)
bytes = event.FixProtocolSpecifier(bytes)
log.Printf("[VERB] %s <- %s", conn.RemoteAddr(), string(bytes))
conn.Write(bytes)
}
}
开发者ID:EmuxEvans,项目名称:hc,代码行数:21,代码来源:ip_transport.go
示例18: HandleGetCharacteristics
// HandleGetCharacteristics handles a get characteristic request.
func (ctr *CharacteristicController) HandleGetCharacteristics(form url.Values) (io.Reader, error) {
var b bytes.Buffer
aid, cid, err := ParseAccessoryAndCharacterID(form.Get("id"))
containerChar := ctr.GetCharacteristic(aid, cid)
if containerChar == nil {
log.Printf("[WARN] No characteristic found with aid %d and iid %d\n", aid, cid)
return &b, nil
}
chars := data.NewCharacteristics()
char := data.Characteristic{AccessoryID: aid, ID: cid, Value: containerChar.GetValue(), Events: containerChar.EventsEnabled()}
chars.AddCharacteristic(char)
result, err := json.Marshal(chars)
if err != nil {
log.Println("[ERRO]", err)
}
b.Write(result)
return &b, err
}
开发者ID:smitterson,项目名称:hc,代码行数:22,代码来源:characteristic_controller.go
示例19: ServeHTTP
func (endpoint *PairSetup) ServeHTTP(response http.ResponseWriter, request *http.Request) {
log.Printf("[VERB] %v POST /pair-setup", request.RemoteAddr)
response.Header().Set("Content-Type", netio.HTTPContentTypePairingTLV8)
var err error
var in util.Container
var out util.Container
key := endpoint.context.GetConnectionKey(request)
session := endpoint.context.Get(key).(netio.Session)
ctrl := session.PairSetupHandler()
if ctrl == nil {
log.Println("[VERB] Create new pair setup controller")
if ctrl, err = pair.NewSetupServerController(endpoint.device, endpoint.database); err != nil {
log.Println(err)
}
session.SetPairSetupHandler(ctrl)
}
if in, err = util.NewTLV8ContainerFromReader(request.Body); err == nil {
out, err = ctrl.Handle(in)
}
if err != nil {
log.Println("[ERRO]", err)
response.WriteHeader(http.StatusInternalServerError)
} else {
io.Copy(response, out.BytesBuffer())
// Send event when key exchange is done
b := out.GetByte(pair.TagSequence)
switch pair.PairStepType(b) {
case pair.PairStepKeyExchangeResponse:
endpoint.emitter.Emit(event.DevicePaired{})
}
}
}
开发者ID:smitterson,项目名称:hc,代码行数:39,代码来源:pair-setup.go
示例20: ServeHTTP
func (handler *Accessories) ServeHTTP(response http.ResponseWriter, request *http.Request) {
log.Printf("[VERB] %v GET /accessories", request.RemoteAddr)
response.Header().Set("Content-Type", netio.HTTPContentTypeHAPJson)
handler.mutex.Lock()
res, err := handler.controller.HandleGetAccessories(request.Body)
handler.mutex.Unlock()
if err != nil {
log.Println("[ERRO]", err)
response.WriteHeader(http.StatusInternalServerError)
} else {
// Write the data in chunks of 2048 bytes
// http.ResponseWriter should do this already, but crashes because of an unkown reason
wr := netio.NewChunkedWriter(response, 2048)
b, _ := ioutil.ReadAll(res)
log.Println("[VERB]", string(b))
_, err := wr.Write(b)
if err != nil {
log.Println("[ERRO]", err)
}
}
}
开发者ID:smitterson,项目名称:hc,代码行数:23,代码来源:accessories.go
注:本文中的github.com/brutella/log.Printf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论