本文整理汇总了Golang中github.com/brutella/log.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Printf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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")
}
}
示例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)
}
}
}
示例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
}
}
示例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)
}
示例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
}
示例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)
}
}
}
示例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)
}
}
示例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{})
}
}
}
示例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))
})
}
示例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
}
示例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()
}
示例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)
}
}
示例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
}
示例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)
}
}
示例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
}