本文整理汇总了Golang中github.com/Cepave/alarm/g.Config函数的典型用法代码示例。如果您正苦于以下问题:Golang Config函数的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Config函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: ReadLowEvent
func ReadLowEvent() {
queues := g.Config().Redis.LowQueues
if len(queues) == 0 {
return
}
for {
event, err := popEvent(queues)
if err != nil {
time.Sleep(time.Second)
continue
}
consume(event, false)
}
}
开发者ID:donh,项目名称:alarm,代码行数:15,代码来源:reader.go
示例17: CurlUic
func CurlUic(team string) []*User {
if team == "" {
return []*User{}
}
uri := fmt.Sprintf("%s/team/users", g.Config().Api.Uic)
req := httplib.Get(uri).SetTimeout(2*time.Second, 10*time.Second)
req.Param("name", team)
req.Param("token", g.Config().UicToken)
var usersWrap UsersWrap
err := req.ToJson(&usersWrap)
if err != nil {
log.Printf("curl %s fail: %v", uri, err)
return nil
}
if usersWrap.Msg != "" {
log.Printf("curl %s return msg: %v", uri, usersWrap.Msg)
return nil
}
return usersWrap.Users
}
开发者ID:myhung,项目名称:alarm,代码行数:24,代码来源:uic.go
示例18: Index
func (this *MainController) Index() {
if false == g.Config().Debug {
sig := this.Ctx.GetCookie("sig")
isLoggedIn := CheckLoginStatusByCookie(sig)
if !isLoggedIn {
RedirectUrl := g.Config().RedirectUrl
this.Redirect(RedirectUrl, 302)
}
}
events := g.Events.Clone()
defer func() {
this.Data["Now"] = time.Now().Unix()
this.TplNames = "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
}()
if len(events) == 0 {
this.Data["Events"] = []*g.EventDto{}
return
}
count := len(events)
if count == 0 {
this.Data["Events"] = []*g.EventDto{}
return
}
// 按照持续时间排序
beforeOrder := make([]*g.EventDto, count)
i := 0
for _, event := range events {
beforeOrder[i] = event
i++
}
sort.Sort(g.OrderedEvents(beforeOrder))
this.Data["Events"] = beforeOrder
}
开发者ID:myhung,项目名称:alarm,代码行数:46,代码来源:controller.go
示例19: CurlAction
func CurlAction(id int) *Action {
if id <= 0 {
return nil
}
uri := fmt.Sprintf("%s/api/action/%d", g.Config().Api.Portal, id)
req := httplib.Get(uri).SetTimeout(5*time.Second, 30*time.Second)
var actionWrap ActionWrap
err := req.ToJson(&actionWrap)
if err != nil {
log.Printf("curl %s fail: %v", uri, err)
return nil
}
if actionWrap.Msg != "" {
log.Printf("curl %s return msg: %v", uri, actionWrap.Msg)
return nil
}
return actionWrap.Data
}
开发者ID:myhung,项目名称:alarm,代码行数:22,代码来源:portal.go
示例20: popEvent
func popEvent(queues []string) (*model.Event, error) {
count := len(queues)
params := make([]interface{}, count+1)
for i := 0; i < count; i++ {
params[i] = queues[i]
}
// set timeout 0
params[count] = 0
rc := g.RedisConnPool.Get()
defer rc.Close()
reply, err := redis.Strings(rc.Do("BRPOP", params...))
if err != nil {
log.Printf("get alarm event from redis fail: %v", err)
return nil, err
}
var event model.Event
err = json.Unmarshal([]byte(reply[1]), &event)
if err != nil {
log.Printf("parse alarm event fail: %v", err)
return nil, err
}
if g.Config().Debug {
log.Println("======>>>>")
log.Println(event.String())
}
// save in memory. display in dashboard
g.Events.Put(&event)
return &event, nil
}
开发者ID:myhung,项目名称:alarm,代码行数:37,代码来源:reader.go
注:本文中的github.com/Cepave/alarm/g.Config函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论