當前位置: 首頁>>代碼示例>>Golang>>正文


Golang g.Config函數代碼示例

本文整理匯總了Golang中github.com/Cepave/alarm/g.Config函數的典型用法代碼示例。如果您正苦於以下問題:Golang Config函數的具體用法?Golang Config怎麽用?Golang Config使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Config函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: checkLogin

func checkLogin(m *MainController) bool {
	// Skip the login check in debug mode.
	if g.Config().Debug {
		return true
	}

	sig := m.Ctx.GetCookie("sig")
	isLoggedIn := CheckLoginStatusByCookie(sig)
	if !isLoggedIn {
		RedirectUrl := g.Config().RedirectUrl
		m.Redirect(RedirectUrl, 302)
		return false
	}
	return true
}
開發者ID:donh,項目名稱:alarm,代碼行數:15,代碼來源:controller.go

示例2: LinkToSMS

func LinkToSMS(content string) (string, error) {
	links := g.Config().Api.Links
	uri := fmt.Sprintf("%s/store", links)
	req := httplib.Post(uri).SetTimeout(3*time.Second, 10*time.Second)
	req.Body([]byte(content))
	return req.String()
}
開發者ID:myhung,項目名稱:alarm,代碼行數:7,代碼來源:links.go

示例3: ParseUserSms

func ParseUserSms(event *model.Event, action *api.Action) {
	userMap := api.GetUsers(action.Uic)

	content := GenerateSmsContent(event)
	metric := event.Metric()
	status := event.Status
	priority := event.Priority()

	queue := g.Config().Redis.UserSmsQueue

	rc := g.RedisConnPool.Get()
	defer rc.Close()

	for _, user := range userMap {
		dto := SmsDto{
			Priority: priority,
			Metric:   metric,
			Content:  content,
			Phone:    user.Phone,
			Status:   status,
		}
		bs, err := json.Marshal(dto)
		if err != nil {
			log.Println("json marshal SmsDto fail:", err)
			continue
		}

		_, err = rc.Do("LPUSH", queue, string(bs))
		if err != nil {
			log.Println("LPUSH redis", queue, "fail:", err, "dto:", string(bs))
		}
	}
}
開發者ID:myhung,項目名稱:alarm,代碼行數:33,代碼來源:consumer.go

示例4: Index

func (this *MainController) Index() {
	if checkLogin(this) == false {
		return
	}
	defer func() {
		this.Data["Now"] = time.Now().Unix()
		this.TplName = "index.html"
		this.Data["FalconPortal"] = g.Config().Shortcut.FalconPortal
		this.Data["FalconDashboard"] = g.Config().Shortcut.FalconDashboard
		this.Data["GrafanaDashboard"] = g.Config().Shortcut.GrafanaDashboard
		this.Data["FalconAlarm"] = g.Config().Shortcut.FalconAlarm
		this.Data["FalconUIC"] = g.Config().Shortcut.FalconUIC
	}()

	this.Data["Events"] = g.Events.CloneToOrderedEvents()
}
開發者ID:donh,項目名稱:alarm,代碼行數:16,代碼來源:controller.go

示例5: popAllServerchanDto

func popAllServerchanDto() []*ServerchanDto {
	ret := []*ServerchanDto{}
	queue := g.Config().Redis.UserServerchanQueue

	rc := g.RedisConnPool.Get()
	defer rc.Close()

	for {
		reply, err := redis.String(rc.Do("RPOP", queue))
		if err != nil {
			if err != redis.ErrNil {
				log.Println("get ServerchanDto fail", err)
			}
			break
		}

		if reply == "" || reply == "nil" {
			continue
		}

		var serverchanDto ServerchanDto
		err = json.Unmarshal([]byte(reply), &serverchanDto)
		if err != nil {
			log.Printf("json unmarshal ServerchanDto: %s fail: %v", reply, err)
			continue
		}

		ret = append(ret, &serverchanDto)
	}

	return ret
}
開發者ID:myhung,項目名稱:alarm,代碼行數:32,代碼來源:combine.go

示例6: ConfigReload

func (this *MainController) ConfigReload() {
	remoteAddr := this.Ctx.Input.Context.Request.RemoteAddr
	if strings.HasPrefix(remoteAddr, "127.0.0.1") {
		g.ParseConfig(g.ConfigFile)
		this.Data["json"] = g.Config()
		this.ServeJSON()
	} else {
		this.Ctx.WriteString("no privilege")
	}
}
開發者ID:donh,項目名稱:alarm,代碼行數:10,代碼來源:controller.go

示例7: Start

func Start() {
	if !g.Config().Http.Enabled {
		return
	}

	addr := g.Config().Http.Listen
	if addr == "" {
		return
	}

	if g.Config().Debug {
		beego.BConfig.RunMode = "dev"
	} else {
		beego.BConfig.RunMode = "prod"
	}

	beego.Run(addr)

	log.Println("http listening", addr)
}
開發者ID:donh,項目名稱:alarm,代碼行數:20,代碼來源:http.go

示例8: InitDatabase

func InitDatabase() {
	// set default database
	config := g.Config()
	orm.RegisterDataBase("default", "mysql", config.Uic.Addr, config.Uic.Idle, config.Uic.Max)
	orm.RegisterDataBase("falcon_portal", "mysql", config.FalconPortal.Addr, config.FalconPortal.Idle, config.FalconPortal.Max)
	// register model
	orm.RegisterModel(new(uic.User), new(uic.Session), new(event.Events), new(event.EventCases))
	if config.Debug {
		orm.Debug = true
	}
}
開發者ID:donh,項目名稱:alarm,代碼行數:11,代碼來源:database.go

示例9: InitDatabase

func InitDatabase() {
	// set default database
	config := g.Config()
	orm.RegisterDataBase("default", "mysql", config.Uic.Addr, config.Uic.Idle, config.Uic.Max)

	// register model
	orm.RegisterModel(new(User), new(Session))

	if config.Debug == true {
		orm.Debug = true
	}
}
開發者ID:myhung,項目名稱:alarm,代碼行數:12,代碼來源:http.go

示例10: WriteServerchanModel

func WriteServerchanModel(serverchan *model.Serverchan) {
	if serverchan == nil {
		return
	}

	bs, err := json.Marshal(serverchan)
	if err != nil {
		log.Println(err)
		return
	}

	LPUSH(g.Config().Queue.Serverchan, string(bs))
}
開發者ID:myhung,項目名稱:alarm,代碼行數:13,代碼來源:sender.go

示例11: WriteQQModel

func WriteQQModel(qq *model.QQ) {
	if qq == nil {
		return
	}

	bs, err := json.Marshal(qq)
	if err != nil {
		log.Println(err)
		return
	}

	LPUSH(g.Config().Queue.QQ, string(bs))
}
開發者ID:myhung,項目名稱:alarm,代碼行數:13,代碼來源:sender.go

示例12: WriteSmsModel

func WriteSmsModel(sms *model.Sms) {
	if sms == nil {
		return
	}

	bs, err := json.Marshal(sms)
	if err != nil {
		log.Println(err)
		return
	}

	LPUSH(g.Config().Queue.Sms, string(bs))
}
開發者ID:myhung,項目名稱:alarm,代碼行數:13,代碼來源:sender.go

示例13: InitLogger

func InitLogger() {
	config := g.Config()
	if logger == nil {
		logrus.SetFormatter(&logrus.JSONFormatter{})
		logrus.SetOutput(os.Stderr)
		if config.Debug {
			logrus.SetLevel(logrus.DebugLevel)
		} else {
			logrus.SetLevel(logrus.WarnLevel)
		}
		logger = logrus.WithFields(logrus.Fields{})
	}
}
開發者ID:donh,項目名稱:alarm,代碼行數:13,代碼來源:logger.go

示例14: WriteMailModel

func WriteMailModel(mail *model.Mail) {
	if mail == nil {
		return
	}

	bs, err := json.Marshal(mail)
	if err != nil {
		log.Println(err)
		return
	}

	LPUSH(g.Config().Queue.Mail, string(bs))
}
開發者ID:myhung,項目名稱:alarm,代碼行數:13,代碼來源:sender.go

示例15: combineSms

func combineSms() {
	dtos := popAllSmsDto()
	count := len(dtos)
	if count == 0 {
		return
	}

	dtoMap := make(map[string][]*SmsDto)
	for i := 0; i < count; i++ {
		key := fmt.Sprintf("%d%s%s%s", dtos[i].Priority, dtos[i].Status, dtos[i].Phone, dtos[i].Metric)
		if _, ok := dtoMap[key]; ok {
			dtoMap[key] = append(dtoMap[key], dtos[i])
		} else {
			dtoMap[key] = []*SmsDto{dtos[i]}
		}
	}

	for _, arr := range dtoMap {
		size := len(arr)
		if size == 1 {
			redi.WriteSms([]string{arr[0].Phone}, arr[0].Content)
			continue
		}

		// 把多個sms內容寫入數據庫,隻給用戶提供一個鏈接
		contentArr := make([]string, size)
		for i := 0; i < size; i++ {
			contentArr[i] = arr[i].Content
		}
		content := strings.Join(contentArr, ",,")

		first := arr[0].Content
		t := strings.Split(first, "][")
		eg := ""
		if len(t) >= 3 {
			eg = t[2]
		}

		path, err := api.LinkToSMS(content)
		sms := ""
		if err != nil || path == "" {
			sms = fmt.Sprintf("[P%d][%s] %d %s.  e.g. %s detail in email", arr[0].Priority, arr[0].Status, size, arr[0].Metric, eg)
			log.Println("get link fail", err)
		} else {
			links := g.Config().Api.Links
			sms = fmt.Sprintf("[P%d][%s] %d %s e.g. %s %s/%s ", arr[0].Priority, arr[0].Status, size, arr[0].Metric, eg, links, path)
		}

		redi.WriteSms([]string{arr[0].Phone}, sms)
	}
}
開發者ID:myhung,項目名稱:alarm,代碼行數:51,代碼來源:combine.go


注:本文中的github.com/Cepave/alarm/g.Config函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。