当前位置: 首页>>代码示例>>Golang>>正文


Golang g.Config函数代码示例

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


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

示例1: Start

func Start(httpMsg chan<- string) {

	defer func() {
		httpMsg <- "http"
	}()

	if !g.Config().Http.Enabled {
		log.Println("http.Start warning, not enable")
		return
	}

	// config http routes
	configCommonRoutes()
	configProcHttpRoutes()
	configGraphRoutes()
	configAPIRoutes()
	configAlertRoutes()
	configGrafanaRoutes()
	configZabbixRoutes()
	configNqmRoutes()
	configNQMRoutes()

	// start mysql database
	InitDatabase()

	// start http server
	addr := g.Config().Http.Listen
	s := &http.Server{
		Addr:           addr,
		MaxHeaderBytes: 1 << 30,
	}

	log.Println("http.Start ok, listening on", addr)
	log.Fatalln(s.ListenAndServe())
}
开发者ID:donh,项目名称:query,代码行数:35,代码来源:http.go

示例2: getHosts

func getHosts(reqHost string, hostKeyword string) []interface{} {
	if len(hostKeyword) == 0 {
		hostKeyword = ".+"
	}
	rand.Seed(time.Now().UTC().UnixNano())
	random64 := rand.Float64()
	_r := strconv.FormatFloat(random64, 'f', -1, 32)
	maxQuery := g.Config().Api.Max
	url := fmt.Sprintf("/api/endpoints?q=%s&tags&limit=%d&_r=%s&regex_query=1", hostKeyword, maxQuery, _r)
	if strings.Index(g.Config().Api.Query, reqHost) >= 0 {
		url = "http://localhost:9966" + url
	} else {
		url = g.Config().Api.Query + url
	}
	nodes := doHTTPQuery(url)
	result := []interface{}{}
	chart := map[string]interface{}{
		"text":       "chart",
		"expandable": true,
	}
	result = append(result, chart)

	for _, host := range nodes["data"].([]interface{}) {
		item := map[string]interface{}{
			"text":       host,
			"expandable": true,
		}
		result = append(result, item)
	}
	return result
}
开发者ID:donh,项目名称:query,代码行数:31,代码来源:grafana.go

示例3: Start

func Start() {
	if !g.Config().Http.Enable {
		log.Println("http.Start warning, not enable")
		return
	}

	// config http routes
	configCommonRoutes()
	configProcHttpRoutes()
	configGraphRoutes()
	configApiRoutes()
	configGrafanaRoutes()
	configZabbixRoutes()

	// start mysql database
	InitDatabase()

	// start http server
	addr := g.Config().Http.Listen
	s := &http.Server{
		Addr:           addr,
		MaxHeaderBytes: 1 << 30,
	}

	log.Println("http.Start ok, listening on", addr)
	log.Fatalln(s.ListenAndServe())
}
开发者ID:myhung,项目名称:query,代码行数:27,代码来源:http.go

示例4: getHosts

/**
 * @function name:   func getHosts(rw http.ResponseWriter, req *http.Request, hostKeyword string)
 * @description:     This function returns available hosts for Grafana query editor.
 * @related issues:  OWL-221, OWL-151
 * @param:           rw http.ResponseWriter
 * @param:           req *http.Request
 * @param:           hostKeyword string
 * @return:          void
 * @author:          Don Hsieh
 * @since:           11/17/2015
 * @last modified:   12/18/2015
 * @called by:       func setQueryEditor(rw http.ResponseWriter, req *http.Request, hostKeyword string)
 */
func getHosts(rw http.ResponseWriter, req *http.Request, hostKeyword string) {
	if len(hostKeyword) == 0 {
		hostKeyword = ".+"
	}
	rand.Seed(time.Now().UTC().UnixNano())
	random64 := rand.Float64()
	_r := strconv.FormatFloat(random64, 'f', -1, 32)
	maxQuery := strconv.Itoa(g.Config().Api.Max)
	url := "/api/endpoints" + "?q=" + hostKeyword + "&tags&limit=" + maxQuery + "&_r=" + _r + "&regex_query=1"
	log.Println("req.Host =", req.Host)
	log.Println("g.Config().Api.Query =", g.Config().Api.Query)
	log.Println("maxQuery = ", maxQuery)
	if strings.Index(g.Config().Api.Query, req.Host) >= 0 {
		url = "http://localhost:9966" + url
	} else {
		url = g.Config().Api.Query + url
	}
	log.Println("url =", url)

	reqGet, err := http.NewRequest("GET", url, nil)
	if err != nil {
		log.Println("Error =", err.Error())
	}

	client := &http.Client{}
	resp, err := client.Do(reqGet)
	if err != nil {
		log.Println("Error =", err.Error())
	}
	defer resp.Body.Close()

	result := []interface{}{}
	chart := map[string]interface{}{
		"text":       "chart",
		"expandable": true,
	}
	result = append(result, chart)

	if resp.Status == "200 OK" {
		body, _ := ioutil.ReadAll(resp.Body)
		var nodes = make(map[string]interface{})
		if err := json.Unmarshal(body, &nodes); err != nil {
			log.Println(err.Error())
		}
		for _, host := range nodes["data"].([]interface{}) {
			item := map[string]interface{}{
				"text":       host,
				"expandable": true,
			}
			result = append(result, item)
		}
		RenderJson(rw, result)
	} else {
		RenderJson(rw, result)
	}
}
开发者ID:myhung,项目名称:query,代码行数:69,代码来源:grafana.go

示例5: getLocation

func getLocation(pop_id int) map[string]string {
	location := map[string]string{
		"area":     "",
		"province": "",
		"city":     "",
	}
	fcname := g.Config().Api.Name
	fctoken := getFctoken()
	url := g.Config().Api.Geo

	args := map[string]interface{}{
		"fcname":  fcname,
		"fctoken": fctoken,
		"pop_id":  pop_id,
	}
	bs, err := json.Marshal(args)
	if err != nil {
		log.Println("Error =", err.Error())
	}

	reqPost, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(bs)))
	if err != nil {
		log.Println("Error =", err.Error())
	}
	reqPost.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(reqPost)
	if err != nil {
		log.Println("Error =", err.Error())
	}
	defer resp.Body.Close()

	if resp.Status == "200 OK" {
		body, _ := ioutil.ReadAll(resp.Body)
		nodes := map[string]interface{}{}
		if err := json.Unmarshal(body, &nodes); err != nil {
			log.Println(err.Error())
		}
		status := int(nodes["status"].(float64))
		if status == 1 {
			result := nodes["result"]
			location["area"] = result.(map[string]interface{})["area"].(string)
			location["province"] = result.(map[string]interface{})["province"].(string)
			location["city"] = result.(map[string]interface{})["city"].(string)
		}
	}
	return location
}
开发者ID:donh,项目名称:query,代码行数:49,代码来源:grafana_graph_options.go

示例6: queryAgentAlive

func queryAgentAlive(queries []*cmodel.GraphLastParam, reqHost string, result map[string]interface{}) []cmodel.GraphLastResp {
	data := []cmodel.GraphLastResp{}
	if len(queries) > 0 {
		if strings.Index(g.Config().Api.Query, reqHost) >= 0 {
			proc.LastRequestCnt.Incr()
			for _, param := range queries {
				if param == nil {
					continue
				}
				last, err := graph.Last(*param)
				if err != nil {
					log.Printf("graph.last fail, resp: %v, err: %v", last, err)
				}
				if last == nil {
					continue
				}
				data = append(data, *last)
			}
			proc.LastRequestItemCnt.IncrBy(int64(len(data)))
		} else {
			s, err := json.Marshal(queries)
			if err != nil {
				setError(err.Error(), result)
			}
			url := g.Config().Api.Query + "/graph/last"
			reqPost, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(s)))
			if err != nil {
				setError(err.Error(), result)
			}
			reqPost.Header.Set("Content-Type", "application/json")

			client := &http.Client{}
			resp, err := client.Do(reqPost)
			if err != nil {
				setError(err.Error(), result)
			}
			defer resp.Body.Close()

			body, _ := ioutil.ReadAll(resp.Body)

			err = json.Unmarshal(body, &data)
			if err != nil {
				setError(err.Error(), result)
			}
		}
	}
	return data
}
开发者ID:donh,项目名称:query,代码行数:48,代码来源:api.go

示例7: Init

func Init() {
	conf := g.Config()
	db, err = gorm.Open("mysql", conf.GraphDB.Addr)
	if err != nil {
		log.Println(err.Error())
	}
}
开发者ID:donh,项目名称:query,代码行数:7,代码来源:init.go

示例8: main

func main() {
	cfg := flag.String("c", "cfg.json", "specify config file")
	version := flag.Bool("v", false, "show version")
	versionGit := flag.Bool("vg", false, "show version and git commit log")
	flag.Parse()

	if *version {
		fmt.Println(g.VERSION)
		os.Exit(0)
	}
	if *versionGit {
		fmt.Println(g.VERSION, g.COMMIT)
		os.Exit(0)
	}

	// config
	g.ParseConfig(*cfg)
	gconf := g.Config()
	// proc
	proc.Start()

	// graph
	graph.Start()

	grpcMsg := make(chan string)
	if gconf.Grpc.Enabled {
		// grpc
		go grpc.Start(grpcMsg)
	}

	ginMsg := make(chan string)

	if gconf.GinHttp.Enabled {
		//lambdaSetup
		database.Init()
		conf.ReadConf("./conf/lambdaSetup.json")
		go ginHttp.StartWeb(ginMsg)
	}

	httpMsg := make(chan string)

	if gconf.Http.Enabled {
		// http
		go http.Start(httpMsg)
	}

	select {
	case <-grpcMsg:
		log.Printf("%v is crashed", grpcMsg)
	case <-ginMsg:
		log.Printf("%v is crashed", ginMsg)
	case <-httpMsg:
		log.Printf("%v is crashed", ginMsg)
	}
}
开发者ID:donh,项目名称:query,代码行数:55,代码来源:main.go

示例9: initConnPools

// internal functions
func initConnPools() {
	cfg := g.Config()

	// TODO 为了得到Slice,这里做的太复杂了
	graphInstances := nset.NewSafeSet()
	for _, address := range cfg.Graph.Cluster {
		graphInstances.Add(address)
	}
	GraphConnPools = spool.CreateSafeRpcConnPools(cfg.Graph.MaxConns, cfg.Graph.MaxIdle,
		cfg.Graph.ConnTimeout, cfg.Graph.CallTimeout, graphInstances.ToSlice())
}
开发者ID:donh,项目名称:query,代码行数:12,代码来源:graph.go

示例10: Info

func Info(para cmodel.GraphInfoParam) (resp *cmodel.GraphFullyInfo, err error) {
	endpoint, counter := para.Endpoint, para.Counter

	pool, addr, err := selectPool(endpoint, counter)
	if err != nil {
		return nil, err
	}

	conn, err := pool.Fetch()
	if err != nil {
		return nil, err
	}

	rpcConn := conn.(spool.RpcClient)
	if rpcConn.Closed() {
		pool.ForceClose(conn)
		return nil, errors.New("conn closed")
	}

	type ChResult struct {
		Err  error
		Resp *cmodel.GraphInfoResp
	}
	ch := make(chan *ChResult, 1)
	go func() {
		resp := &cmodel.GraphInfoResp{}
		err := rpcConn.Call("Graph.Info", para, resp)
		ch <- &ChResult{Err: err, Resp: resp}
	}()

	select {
	case <-time.After(time.Duration(g.Config().Graph.CallTimeout) * time.Millisecond):
		pool.ForceClose(conn)
		return nil, fmt.Errorf("%s, call timeout. proc: %s", addr, pool.Proc())
	case r := <-ch:
		if r.Err != nil {
			pool.ForceClose(conn)
			return nil, fmt.Errorf("%s, call failed, err %v. proc: %s", addr, r.Err, pool.Proc())
		} else {
			pool.Release(conn)
			fullyInfo := cmodel.GraphFullyInfo{
				Endpoint:  endpoint,
				Counter:   counter,
				ConsolFun: r.Resp.ConsolFun,
				Step:      r.Resp.Step,
				Filename:  r.Resp.Filename,
				Addr:      addr,
			}
			return &fullyInfo, nil
		}
	}
}
开发者ID:donh,项目名称:query,代码行数:52,代码来源:graph.go

示例11: getPlatformJSON

func getPlatformJSON(nodes map[string]interface{}, result map[string]interface{}) {
	fcname := g.Config().Api.Name
	fctoken := getFctoken()
	url := g.Config().Api.Map + "/fcname/" + fcname + "/fctoken/" + fctoken
	url += "/show_active/yes/hostname/yes/pop_id/yes/ip/yes.json"

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		setError(err.Error(), result)
	}

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		setError(err.Error(), result)
	}
	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)
	if err := json.Unmarshal(body, &nodes); err != nil {
		setError(err.Error(), result)
	}
}
开发者ID:donh,项目名称:query,代码行数:23,代码来源:api.go

示例12: getFctoken

/**
 * @function name:   func getFctoken() fctoken string
 * @description:     This function returns fctoken for API request.
 * @related issues:  OWL-159
 * @param:           void
 * @return:          fctoken string
 * @author:          Don Hsieh
 * @since:           11/24/2015
 * @last modified:   11/24/2015
 * @called by:       func apiAlert(rw http.ResponseWriter, req *http.Request)
 *                    in query/http/zabbix.go
 *                   func getMapValues(chartType string) map[string]interface{}
 *                    in query/http/grafana.go
 */
func getFctoken() string {
	hasher := md5.New()
	io.WriteString(hasher, g.Config().Api.Token)
	s := hex.EncodeToString(hasher.Sum(nil))

	t := time.Now()
	now := t.Format("20060102")
	s = now + s

	hasher = md5.New()
	io.WriteString(hasher, s)
	fctoken := hex.EncodeToString(hasher.Sum(nil))
	return fctoken
}
开发者ID:chyeh,项目名称:query,代码行数:28,代码来源:zabbix.go

示例13: InitDatabase

func InitDatabase() {
	// set default database
	config := g.Config()
	orm.RegisterDataBase("default", "mysql", config.Db.Addr, config.Db.Idle, config.Db.Max)
	// register model
	orm.RegisterModel(new(Host), new(Grp), new(Grp_host), new(Grp_tpl), new(Tpl))

	strConn := strings.Replace(config.Db.Addr, "graph", "grafana", 1)
	orm.RegisterDataBase("grafana", "mysql", strConn, config.Db.Idle, config.Db.Max)
	orm.RegisterModel(new(Province), new(City), new(Idc))

	if config.Debug == true {
		orm.Debug = true
	}
}
开发者ID:myhung,项目名称:query,代码行数:15,代码来源:http.go

示例14: configCommonRoutes

func configCommonRoutes() {
	http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok\n"))
	})

	http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(fmt.Sprintf("%s\n", g.VERSION)))
	})

	http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(fmt.Sprintf("%s\n", file.SelfDir())))
	})

	http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, g.Config())
	})

}
开发者ID:myhung,项目名称:query,代码行数:18,代码来源:common.go

示例15: outputJsonForPanic

// Used to output JSON message even if the execution is panic
func outputJsonForPanic(ctx *context.Context) {
	r := recover()
	if r == nil {
		return
	}

	if g.Config().Debug {
		debug.PrintStack()
	}

	log.Printf("Error on HTTP Request[%v/%v]. Error: %v", ctx.Input.Method(), ctx.Input.URI(), r)

	ctx.Output.SetStatus(http.StatusBadRequest)
	ctx.Output.JSON(&jsonDslError{
		Code:    -1,
		Message: fmt.Sprintf("%v", r),
	}, jsonIndent, jsonCoding)
}
开发者ID:donh,项目名称:query,代码行数:19,代码来源:nqm.go


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