• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log.Println函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/brutella/log.Println函数的典型用法代码示例。如果您正苦于以下问题:Golang Println函数的具体用法?Golang Println怎么用?Golang Println使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Println函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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


示例2: 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


示例3: 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


示例4: 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


示例5: RunLoop

func (t *Thermostat) RunLoop() {
	go t.boiler.RunLoop()

	for {
		select {
		case <-time.After(interval):
			temp = t.thermometer.Temperature()

			if temp >= t.targetTemp+maxOver {
				if t.boiler.GetCurrentCommand() == true {
					log.Println("[INFO] Over temperature, turning boiler off")
					t.boiler.SetCurrentCommand(false)
					t.isOn = false
				}
			} else if temp <= t.targetTemp-minUnder {
				if t.boiler.GetCurrentCommand() == false {
					log.Println("[INFO] Under temperature, turning boiler on")
					t.boiler.SetCurrentCommand(true)
					t.isOn = true
				}
			}
		case <-t.done:
			break
		}
	}

	t.boiler.Stop()
}
开发者ID:tomtaylor,项目名称:heating,代码行数:28,代码来源:thermostat.go


示例6: 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


示例7: main

func main() {
	flag.Float64Var(&temp, "temp", 20.0, "Target temperature")
	flag.StringVar(&tempPath, "tempPath", "", "Target temperature path")
	flag.StringVar(&device, "device", "", "Thermometer device")
	flag.BoolVar(&verbose, "verbose", false, "Verbose logging")
	flag.Parse()

	log.Verbose = verbose

	if device == "" {
		log.Fatal("No device specified")
	}

	if tempPath != "" {
		_, err := os.Stat(tempPath)
		if err != nil {
			log.Fatal(err)
		}

		log.Println("[INFO] Starting thermostat with temperature from path:", tempPath)
	} else {
		log.Println("[INFO] Starting thermostat with target temperature:", temp)
	}

	log.Println("[VERB] Using thermometer at", device)

	boiler := NewBoiler()
	thermometer := NewThermometer(device)
	go thermometer.RunLoop()

	thermostat := NewThermostat(boiler, thermometer, temp)
	go thermostat.RunLoop()

	if tempPath != "" {
		tempPoller := NewTempPoller(thermostat, tempPath)
		temp = tempPoller.PollTemp()
		go tempPoller.RunLoop()
	}

	api := NewAPI(thermostat)
	go api.RunLoop()

	homekitService := NewHomeKitService(thermostat)
	go homekitService.RunLoop()

	// Handle SIGINT and SIGTERM.
	ch := make(chan os.Signal)
	signal.Notify(ch, os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM)
	signal := <-ch
	log.Println("[INFO] Received signal", signal, "terminating")

	homekitService.Stop()
	thermostat.Stop()
}
开发者ID:tomtaylor,项目名称:heating,代码行数:54,代码来源:main.go


示例8: handlePairStart

// Client -> Server
// - Auth start
//
// Server -> Client
// - B: server public key
// - s: salt
func (setup *SetupServerController) handlePairStart(in util.Container) (util.Container, error) {
	out := util.NewTLV8Container()
	setup.step = PairStepStartResponse

	out.SetByte(TagSequence, setup.step.Byte())
	out.SetBytes(TagPublicKey, setup.session.PublicKey)
	out.SetBytes(TagSalt, setup.session.Salt)

	log.Println("[VERB] <-     B:", hex.EncodeToString(out.GetBytes(TagPublicKey)))
	log.Println("[VERB] <-     s:", hex.EncodeToString(out.GetBytes(TagSalt)))

	return out, nil
}
开发者ID:smitterson,项目名称:hc,代码行数:19,代码来源:setup_server_controller.go


示例9: Handle

// Handle processes a container to pair (exchange keys) with an accessory.
func (setup *SetupClientController) Handle(in util.Container) (util.Container, error) {
	method := pairMethodType(in.GetByte(TagPairingMethod))

	// It is valid that method is not sent
	// If method is sent then it must be 0x00
	if method != PairingMethodDefault {
		return nil, errInvalidPairMethod(method)
	}

	code := errCode(in.GetByte(TagErrCode))
	if code != ErrCodeNo {
		log.Println("[ERRO]", code)
		return nil, code.Error()
	}

	seq := pairStepType(in.GetByte(TagSequence))

	var out util.Container
	var err error

	switch seq {
	case PairStepStartResponse:
		out, err = setup.handlePairStepStartResponse(in)
	case PairStepVerifyResponse:
		out, err = setup.handlePairStepVerifyResponse(in)
	case PairStepKeyExchangeResponse:
		out, err = setup.handleKeyExchange(in)
	default:
		return nil, errInvalidPairStep(seq)
	}

	return out, err
}
开发者ID:tjbx,项目名称:X10Bridge,代码行数:34,代码来源:setup_client_controller.go


示例10: 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


示例11: HandleInputValueWithName

func HandleInputValueWithName(v uvr.Value, name string) (s *hkuvr1611.Sensor) {
	var found bool
	if s, found = sensors[name]; found == false {
		s = hkuvr1611.NewSensorForInputValue(v, InfoForAccessoryName(name))
		if s != nil {
			log.Println("[INFO]", reflect.TypeOf(s.Model), "with name", name)
			sensors[name] = s
		}
	} else {
		err := hkuvr1611.UpdateAccessoryWithInputValue(s.Model, v)
		if err != nil {
			log.Println("[ERRO]", err)
		}
	}
	return s
}
开发者ID:brutella,项目名称:hkuvr1611,代码行数:16,代码来源:hkuvr1611d.go


示例12: 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


示例13: 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


示例14: updateTemp

func (tp *TempPoller) updateTemp() {
	temp := tp.PollTemp()
	if temp != tp.lastTemp {
		log.Println("[INFO] Setting thermostat target temperature to", temp)
		tp.thermostat.targetTemp = temp
		tp.lastTemp = temp
	}
}
开发者ID:tomtaylor,项目名称:heating,代码行数:8,代码来源:temp_poller.go


示例15: HandleOutletWithName

func HandleOutletWithName(o uvr1611.Outlet, name string) (s *hkuvr1611.Sensor) {
	var found bool
	if s, found = sensors[name]; found == false {
		s = hkuvr1611.NewSensorForOutlet(o, InfoForAccessoryName(name))
		if s != nil {
			log.Println("[INFO]", reflect.TypeOf(s.Model), "with name", name)
			sensors[name] = s
		}
	} else {
		err := hkuvr1611.UpdateAccessoryWithOutlet(s.Model, o)
		if err != nil {
			log.Println("[ERRO]", err)
		}
	}

	return s
}
开发者ID:brutella,项目名称:hkuvr1611,代码行数:17,代码来源:hkuvr1611d.go


示例16: Close

// Close closes the connection and deletes the related session from the context.
func (con *HAPConnection) Close() error {
	log.Println("[INFO] Close connection and remove session")

	// Remove session from the context
	con.context.DeleteSessionForConnection(con.connection)

	return con.connection.Close()
}
开发者ID:smitterson,项目名称:hc,代码行数:9,代码来源:connection.go


示例17: 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


示例18: NewHomeKitService

func NewHomeKitService(thermostat *Thermostat) *HomeKitService {
	thermostatInfo := model.Info{
		Name: "Thermostat",
	}

	hkThermostat := accessory.NewThermostat(thermostatInfo, temp, 17, 25, 0.5)
	hkThermostat.SetTargetMode(model.HeatCoolModeHeat)
	hkThermostat.OnTargetTempChange(func(temp float64) {
		log.Println("[INFO] HomeKit requested thermostat to change to", temp)
		thermostat.targetTemp = temp
	})

	hkThermostat.OnTargetModeChange(func(mode model.HeatCoolModeType) {
		log.Println("[INFO] HomeKit requested thermostat to change to", mode)

		switch mode {
		case model.HeatCoolModeHeat:
			log.Println("[INFO] HomeKit setting thermostat to default on temp of", defaultOnTemp)
			thermostat.targetTemp = defaultOnTemp
		case model.HeatCoolModeOff:
			log.Println("[INFO] HomeKit setting thermostat to default off temp of", defaultOffTemp)
			thermostat.targetTemp = defaultOffTemp
		case model.HeatCoolModeAuto, model.HeatCoolModeCool:
			hkThermostat.SetTargetMode(model.HeatCoolModeHeat)
		}

	})

	transport, err := hap.NewIPTransport("24282428", hkThermostat.Accessory)
	if err != nil {
		log.Fatal(err)
	}

	t := HomeKitService{
		thermostat:   thermostat,
		done:         make(chan bool),
		hkThermostat: hkThermostat,
		transport:    transport,
	}

	return &t
}
开发者ID:tomtaylor,项目名称:heating,代码行数:42,代码来源:homekit.go


示例19: ExpireDevice

func ExpireDevice(device common.Device) {
	if light, ok := device.(common.Light); ok {
		hkLight, _ := lights[light.ID()]
		light.CloseSubscription(hkLight.sub)
		hkLight.transport.Stop()

		delete(lights, light.ID())
	} else {
		log.Println("[INFO] Unsupported Device")
	}
}
开发者ID:Pmaene,项目名称:hklifx,代码行数:11,代码来源:hklifxd.go


示例20: handlePairVerifyFinish

// Server -> Client
// - only sequence number
// - error code (optional)
func (verify *VerifyServerController) handlePairVerifyFinish(in util.Container) (util.Container, error) {
	verify.step = VerifyStepFinishResponse

	data := in.GetBytes(TagEncryptedData)
	message := data[:(len(data) - 16)]
	var mac [16]byte
	copy(mac[:], data[len(message):]) // 16 byte (MAC)
	log.Println("[VERB] ->     Message:", hex.EncodeToString(message))
	log.Println("[VERB] ->     MAC:", hex.EncodeToString(mac[:]))

	decryptedBytes, err := chacha20poly1305.DecryptAndVerify(verify.session.EncryptionKey[:], []byte("PV-Msg03"), message, mac, nil)

	out := util.NewTLV8Container()
	out.SetByte(TagSequence, verify.step.Byte())

	if err != nil {
		verify.reset()
		log.Println("[ERRO]", err)
		out.SetByte(TagErrCode, ErrCodeAuthenticationFailed.Byte()) // return error 2
	} else {
		in, err := util.NewTLV8ContainerFromReader(bytes.NewBuffer(decryptedBytes))
		if err != nil {
			return nil, err
		}

		username := in.GetString(TagUsername)
		signature := in.GetBytes(TagSignature)
		log.Println("[VERB]     client:", username)
		log.Println("[VERB]  signature:", hex.EncodeToString(signature))

		entity := verify.database.EntityWithName(username)
		if entity == nil {
			return nil, fmt.Errorf("Client %s is unknown", username)
		}

		if len(entity.PublicKey()) == 0 {
			return nil, fmt.Errorf("No LTPK available for client %s", username)
		}

		var material []byte
		material = append(material, verify.session.OtherPublicKey[:]...)
		material = append(material, []byte(username)...)
		material = append(material, verify.session.PublicKey[:]...)

		if crypto.ValidateED25519Signature(entity.PublicKey(), material, signature) == false {
			log.Println("[WARN] signature is invalid")
			verify.reset()
			out.SetByte(TagErrCode, ErrCodeUnknownPeer.Byte()) // return error 4
		} else {
			log.Println("[VERB] signature is valid")
		}
	}

	return out, nil
}
开发者ID:tjbx,项目名称:X10Bridge,代码行数:58,代码来源:verify_server_controller.go



注:本文中的github.com/brutella/log.Println函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-24
下一篇:
Golang log.Printf函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap