本文整理匯總了Golang中github.com/ninjasphere/go-ninja/config.Bool函數的典型用法代碼示例。如果您正苦於以下問題:Golang Bool函數的具體用法?Golang Bool怎麽用?Golang Bool使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Bool函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PostConstruct
func (c *HomeCloud) PostConstruct() error {
c.log = logger.GetLogger("HomeCloud")
c.ExportRPCServices()
c.ensureSiteExists()
ledController := c.Conn.GetServiceClient("$home/led-controller")
err := ledController.Call("enableControl", nil, nil, 0)
if err != nil {
c.log.Infof("Failed to enable control on LED controller: %s", err)
}
if syncEnabled {
// We wait for at least one sync to happen, or fail
<-c.StartSyncing(config.MustDuration("homecloud.sync.interval"))
}
// This is required to enable sphere-reset to clear out redis, then push this empty db to
// cloud.
if config.Bool(false, "clearcloud") {
c.log.Infof("Just clearing cloud so exiting now!")
os.Exit(0)
}
c.AutoStartModules()
return nil
}
示例2: refreshMeshInfo
func refreshMeshInfo() (*meshInfo, error) {
nodes, err := getNodes()
if err != nil {
return nil, err
}
sites, err := getSites()
if err != nil {
return nil, err
}
node, ok := nodes[config.Serial()]
if !ok {
return nil, errors.New("Could not find our node in the cloud. (race condition?)")
}
site, ok := sites[node.SiteID]
if !ok {
return nil, errors.New("Could not find our node in the cloud. (race condition?)")
}
if config.Bool(false, "forceMaster") {
site.MasterNodeID = config.Serial()
}
meshInfo := &meshInfo{
SiteID: site.ID,
MasterNodeID: site.MasterNodeID,
SiteUpdated: int(time.Time(site.Updated).UnixNano() / int64(time.Second)),
}
return meshInfo, saveMeshInfo(meshInfo)
}
示例3: main
func main() {
/*
go func() {
log.Printf("Starting pprof server")
log.Println(http.ListenAndServe(":6060", nil))
}()
//*/
log := logger.GetLogger("LED-controller")
conn, err := ninja.Connect(drivername)
if err != nil {
log.FatalErrorf(err, "Failed to connect to mqtt")
}
controller, err := NewLedController(conn)
if err != nil {
log.FatalErrorf(err, "Failed to create led controller")
}
enableControl := config.Bool(false, "enableControl")
controller.start(enableControl)
blah := make(chan os.Signal, 1)
signal.Notify(blah, os.Interrupt, os.Kill)
// Block until a signal is received.
x := <-blah
log.Infof("Got signal:", x)
}
示例4: ExportDriver
// ExportDriver Exports a driver using the 'driver' protocol, and announces it
func (c *Connection) ExportDriver(driver Driver) error {
time.Sleep(config.Duration(time.Second*3, "drivers.startUpDelay"))
topic := fmt.Sprintf("$node/%s/driver/%s", config.Serial(), driver.GetModuleInfo().ID)
announcement := driver.GetModuleInfo()
announcement.ServiceAnnouncement = model.ServiceAnnouncement{
Schema: "http://schema.ninjablocks.com/service/driver",
}
_, err := c.exportService(driver, topic, announcement)
if err != nil {
return err
}
if config.Bool(false, "autostart") {
err := c.GetServiceClient(topic).Call("start", struct{}{}, nil, time.Second*20)
if err != nil {
c.log.Fatalf("Failed to autostart driver: %s", err)
}
}
return nil
}
示例5: ExportApp
// ExportApp Exports an app using the 'app' protocol, and announces it
func (c *Connection) ExportApp(app App) error {
if app.GetModuleInfo().ID == "" {
panic("You must provide an ID in the package.json")
}
topic := fmt.Sprintf("$node/%s/app/%s", config.Serial(), app.GetModuleInfo().ID)
announcement := app.GetModuleInfo()
announcement.ServiceAnnouncement = model.ServiceAnnouncement{
Schema: "http://schema.ninjablocks.com/service/app",
}
_, err := c.exportService(app, topic, announcement)
if err != nil {
return err
}
if config.Bool(false, "autostart") {
err := c.GetServiceClient(topic).Call("start", struct{}{}, nil, time.Second*20)
if err != nil {
c.log.Fatalf("Failed to autostart app: %s", err)
}
}
return nil
}
示例6: getClient
func getClient() *http.Client {
client := &http.Client{}
if config.Bool(false, "cloud", "allowSelfSigned") {
log.Warningf("Allowing self-signed cerificate (should only be used to connect to development cloud)")
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
return client
}
示例7: req
func req(url string, data interface{}) error {
client := &http.Client{
Timeout: time.Second * 30,
}
if config.Bool(false, "cloud", "allowSelfSigned") {
log.Warningf("Allowing self-signed cerificate (should only be used to connect to development cloud)")
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
resp, err := client.Get(fmt.Sprintf(url, config.MustString("token")))
if err != nil {
return err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
var response restResponse
err = json.Unmarshal(body, &response)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK || response.Type == "error" {
var data restError
err = json.Unmarshal(response.Data, &data)
if data.Type == "authentication_invalid_token" {
return errorUnauthorised
}
if err != nil {
return err
}
return fmt.Errorf("Error from cloud: %s (%s)", data.Message, data.Type)
}
return json.Unmarshal(response.Data, data)
}
示例8: pair
func (c *client) pair() error {
var boardType string
if config.HasString("boardType") {
boardType = config.MustString("boardType")
} else {
boardType = fmt.Sprintf("custom-%s-%s", runtime.GOOS, runtime.GOARCH)
}
log.Debugf("Board type: %s", boardType)
client := &http.Client{
Timeout: time.Second * 60, // It's 20sec on the server so this *should* be ok
}
if config.Bool(false, "cloud", "allowSelfSigned") {
log.Warningf("Allowing self-signed certificate (should only be used to connect to development cloud)")
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
var creds *credentials
for {
url := fmt.Sprintf(config.MustString("cloud", "activation"), config.Serial(), getLocalIP(), boardType)
log.Debugf("Activating at URL: %s", url)
var err error
creds, err = activate(client, url)
if err != nil {
log.Warningf("Activation error : %s", err)
log.Warningf("Sleeping for 3sec")
time.Sleep(time.Second * 3)
} else if creds != nil {
break
}
}
log.Infof("Got credentials. User: %s", creds.UserID)
return saveCreds(creds)
}
示例9: NewGesturePane
package ui
import (
"image"
"math"
draw2d "github.com/ninjasphere/draw2d/draw2dimg"
"github.com/lucasb-eyer/go-colorful"
"github.com/ninjasphere/gestic-tools/go-gestic-sdk"
"github.com/ninjasphere/go-ninja/config"
)
var enableGesturePane = config.Bool(false, "led.gestures.testPane")
type GesturePane struct {
last *gestic.GestureMessage
}
func NewGesturePane() *GesturePane {
return &GesturePane{}
}
func (p *GesturePane) IsEnabled() bool {
return enableGesturePane
}
func (p *GesturePane) KeepAwake() bool {
return false
}
示例10: syncFS
siteModel := NewSiteModel()
thingModel := NewThingModel()
return []interface{}{
moduleModel, &moduleModel.baseModel,
channelModel, &channelModel.baseModel,
deviceModel, &deviceModel.baseModel,
roomModel, &roomModel.baseModel,
siteModel, &siteModel.baseModel,
thingModel, &thingModel.baseModel,
}
}
var fsSyncLog = logger.GetLogger("FS Sync")
var fsSyncInterval = config.Duration(time.Second, "homecloud.fsSync.minInterval")
var fsSyncEnabled = config.Bool(false, "homecloud.fsSync.enabled")
var fsSyncTask *time.Timer
func syncFS() {
if fsSyncEnabled {
if fsSyncTask == nil {
fsSyncTask = time.AfterFunc(fsSyncInterval, func() {
fsSyncLog.Debugf("Syncing filesystem...")
exec.Command("sync").Output()
})
}
fsSyncTask.Reset(fsSyncInterval)
}
}
示例11: NewCertPane
"encoding/json"
"fmt"
"image"
"image/color"
"regexp"
"github.com/davecgh/go-spew/spew"
"github.com/ninjasphere/gestic-tools/go-gestic-sdk"
"github.com/ninjasphere/go-ninja/bus"
"github.com/ninjasphere/go-ninja/config"
"github.com/ninjasphere/go-ninja/logger"
"github.com/ninjasphere/sphere-go-led-controller/fonts/O4b03b"
)
var enableCertificationPane = config.Bool(false, "led.certification.enabled")
type CertPane struct {
log *logger.Logger
waypoints int
rssi string
tag string
}
func NewCertPane(conn bus.Bus) *CertPane {
log := logger.GetLogger("CertPane")
pane := &CertPane{
log: log,
}
示例12:
"github.com/ninjasphere/gestic-tools/go-gestic-sdk"
"github.com/ninjasphere/go-ninja/api"
"github.com/ninjasphere/go-ninja/config"
"github.com/ninjasphere/go-ninja/logger"
)
const width = 16
const height = 16
var panDuration = config.MustDuration("led.panDuration")
var wakeTransitionDuration = config.MustDuration("led.wakeTransition")
var sleepTransitionDuration = config.MustDuration("led.sleepTransition")
var sleepTimeout = config.MustDuration("led.sleepTimeout")
var forceAllPanes = config.Bool(false, "led.forceAllPanes")
var logGestures = config.Bool(false, "led.gestures.log")
var enableGestures = config.Bool(true, "led.gestures.enable")
type PaneLayout struct {
currentPane int
targetPane int
panes []Pane
lastGesture time.Time
panTween *Tween
panLock sync.Mutex
renderLock sync.Mutex
示例13: addQueuedEvents
package simtime
import (
"container/heap"
"runtime/debug"
"time"
"github.com/ninjasphere/go-ninja/config"
"github.com/ninjasphere/go-ninja/logger"
)
var log = logger.GetLogger("simtime")
var enabled = config.Bool(false, "simtime.enable")
var startOffset = config.Duration(time.Hour*24*30, "simtime.startOffset")
var offset = config.Duration(0, "simtime.offset")
var allowFuture = config.Bool(false, "simtime.allowFuture")
var currentTime = time.Now()
var addQueue = make(chan *event)
var queue = eventQueue{}
var added = make(chan bool)
var tick = make(chan bool)
var start = make(chan bool)
func addQueuedEvents() {
for {
select {
case e := <-addQueue:
示例14: NewClockPane
package ui
import (
"fmt"
"image"
"image/color"
"strings"
"time"
"github.com/ninjasphere/gestic-tools/go-gestic-sdk"
"github.com/ninjasphere/go-ninja/api"
"github.com/ninjasphere/go-ninja/config"
"github.com/ninjasphere/sphere-go-led-controller/fonts/clock"
)
var enableClockPane = config.Bool(true, "led.clock.enabled")
var enableAlarm = config.Bool(true, "led.clock.alarmEnabled")
var alarmFlashTimes = config.Int(2, "led.clock.alarmFlashTimes") * 2
var alarmFlashInterval = config.MustDuration("led.clock.alarmFlashInterval")
type ClockPane struct {
alarm *time.Time
timer *time.Timer
tapThrottle *throttle
lights []*ninja.ServiceClient
tickTock bool
}
func NewClockPane() *ClockPane {
var pane *ClockPane
pane = &ClockPane{
示例15: main
func main() {
log.Infof("Welcome home, Ninja.")
if config.Bool(true, "homecloud.waitForNTP") {
waitForNTP()
}
// The MQTT Connection
conn, err := ninja.Connect("sphere-go-homecloud")
if err != nil {
log.Fatalf("Failed to connect to sphere: %s", err)
}
// An MQTT Connection used for outbound syncing connections
syncConn := &models.SyncConnection{}
syncConn.Conn, err = ninja.Connect("sphere-go-homecloud.sync")
if err != nil {
log.Fatalf("Failed to connect to sphere (sync): %s", err)
}
// Our redis pool
pool := &redis.Pool{
MaxIdle: config.MustInt("homecloud.redis.maxIdle"),
MaxActive: config.Int(10, "homecloud.redis.maxActive"),
IdleTimeout: config.MustDuration("homecloud.redis.idleTimeout"),
Wait: true,
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", fmt.Sprintf("%s:%d", config.String("", "homecloud.redis.host"), config.MustInt("homecloud.redis.port")))
if err != nil {
return nil, err
}
return c, err
},
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
}
// Not pretty.
rpc.RedisPool = pool
// Wait until we connect to redis successfully.
for {
c := pool.Get()
if c.Err() == nil {
c.Close()
break
}
log.Warningf("Failed to connect to redis: %s", c.Err())
time.Sleep(time.Second)
}
// Build the object graph using dependency injection
injectables := []interface{}{}
injectables = append(injectables, pool, conn, syncConn)
injectables = append(injectables, &homecloud.HomeCloud{}, &homecloud.TimeSeriesManager{}, &homecloud.DeviceManager{}, &homecloud.ModuleManager{})
injectables = append(injectables, state.NewStateManager())
injectables = append(injectables, &rest.RestServer{})
injectables = append(injectables, models.GetInjectables()...)
err = inject.Populate(injectables...)
if err != nil {
log.Fatalf("Failed to construct the object graph: %s", err)
}
// Run PostConstruct on any objects that have it
for _, node := range injectables {
if n, ok := node.(postConstructable); ok {
go func(c postConstructable) {
if err := c.PostConstruct(); err != nil {
log.Fatalf("Failed PostConstruct on object %s: %s", reflect.TypeOf(c).String(), err)
}
}(n)
}
}
support.WaitUntilSignal()
// So long, and thanks for all the fish.
}