コード例 #1
0
ファイル: tweetbutton.go プロジェクト: xianxu/go-playground
func main() {
	flag.Parse()
	portOffset := *gostrich.PortOffset
	newBinding := gostrich.UpdatePort(*binding, portOffset)

	conf := rpcx.ReliableServiceConf{
		Name:        "tweetbutton",
		Makers:      makeAll(*cassandras, *cassandraTimeout),
		Retries:     *retries,
		Concurrency: *concurrency,
		Stats:       gostrich.AdminServer().GetStats().Scoped("tbapi"),
		Prober:      rpcx.ProberReqLastFail,
	}
	cas := rpcx.NewReliableService(conf)

	state := ServerState{cas}

	server := http.Server{
		newBinding,
		&state,
		*readTimeout,
		*writeTimeout,
		0,
		nil,
	}
	logger.LogInfo("Tweetbutton starting up...\n")
	go func() {
		logger.LogInfo(server.ListenAndServe())
	}()

	gostrich.StartToLive(nil)
}
コード例 #2
0
ファイル: conf.go プロジェクト: xianxu/tfe
/*
 * Those functions are not thread safe, only meant to be called in init() function.
 */
func GetRules(name string, portOffset int) func() map[string]Rules {
	names := strings.Split(name, ",")
	for i, v := range names {
		names[i] = strings.TrimSpace(v)
	}
	if confs == nil {
		confs = make(map[string]func() map[string]Rules)
		return nil
	}
	return func() map[string]Rules {
		result := make(map[string]Rules)
		for _, n := range names {
			if fn, ok := confs[n]; ok {
				rules := fn()
				for port, r := range rules {
					newPort := gostrich.UpdatePort(port, portOffset)
					if rs, ok := result[newPort]; ok {
						//TODO: duplication detection
						result[newPort] = append([]Rule(rs), []Rule(r)...)
					} else {
						result[newPort] = r
					}
				}
			} else {
				log.Printf("Unknown rule named %v", n)
			}
		}
		for k, v := range result {
			n := make([]string, len(v))
			for i, r := range v {
				n[i] = "\"" + r.GetName() + "\""
			}
			log.Printf("Serving %v rules: %v on port %v", len(v), strings.Join(n, ", "), k)
		}
		return result
	}
}