예제 #1
0
func Start() {
	fmt.Println("Starting Liliput..")
	syslog.Openlog("lilliput", syslog.LOG_PID, syslog.LOG_USER)

	m := martini.Classic()
	// render home page
	m.Use(render.Renderer(render.Options{
		Directory:  "static",
		Extensions: []string{".html"},
		Charset:    "UTF-8",
	}))

	gorelic.InitNewrelicAgent(Get("newrelic.license", "").(string), Get("lilliput.domain", "").(string), true)
	m.Use(gorelic.Handler)

	m.Get("/:token", Redirect)
	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", nil)
	})
	m.Post("/", TinyUrl)
	server := fmt.Sprintf("%s:%s",
		Get("redis.server", ""),
		Get("redis.port", ""))
	m.Map(NewPool(server))

	port := fmt.Sprintf(":%v", Get("lilliput.port", ""))
	fmt.Println("Started on " + port + "...")
	http.Handle("/", m)
	http.ListenAndServe(port, nil)
	m.Run()
}
예제 #2
0
파일: main.go 프로젝트: malston/pezauth
func main() {
	appEnv, _ := cfenv.Current()
	m := martini.Classic()
	newRelic := new(integrations.MyNewRelic).New(appEnv)
	gorelic.InitNewrelicAgent(newRelic.Key, newRelic.App, false)
	m.Use(gorelic.Handler)
	oauth2Client := new(integrations.MyOAuth2).New(appEnv)
	pez.ClientID = oauth2Client.ID
	pez.ClientSecret = oauth2Client.Secret
	rds := new(integrations.MyRedis).New(appEnv)
	emailServer := pez.NewEmailServerFromService(appEnv)
	m.Map(emailServer)
	defer rds.Conn.Close()
	pez.InitSession(m, &redisCreds{
		pass: rds.Pass,
		uri:  rds.URI,
	})
	h := new(integrations.MyHeritage).New(appEnv)
	heritageClient := &heritage{
		Client:   ccclient.New(h.LoginTarget, h.LoginUser, h.LoginPass, new(http.Client)),
		ccTarget: h.CCTarget,
	}
	mngo := new(integrations.MyMongo).New(appEnv)
	defer mngo.Session.Close()

	if _, err := heritageClient.Login(); err == nil {
		pez.InitRoutes(m, rds.Conn, mngo, heritageClient)
		m.Run()

	} else {
		panic(fmt.Sprintf("heritage client login error: %s", err.Error()))
	}
}
예제 #3
0
func StartServerMultiplesBotsHostPort(uri string, pathl string, host string, port string, newrelic *RelicConfig, bots ...*TgBot) {
	var puri *url.URL
	if uri != "" {
		tmpuri, err := url.Parse(uri)
		if err != nil {
			fmt.Printf("Bad URL %s", uri)
			return
		}
		puri = tmpuri
	}

	botsmap := make(map[string]*TgBot)
	for _, bot := range bots {
		tokendiv := strings.Split(bot.Token, ":")
		if len(tokendiv) != 2 {
			return
		}

		tokenpath := fmt.Sprintf("%s%s", tokendiv[0], tokendiv[1])
		botpathl := path.Join(pathl, tokenpath)

		nuri, _ := puri.Parse(botpathl)
		remoteuri := nuri.String()
		res, error := bot.SetWebhook(remoteuri)

		if error != nil {
			ec := res.ErrorCode
			fmt.Printf("Error setting the webhook: \nError code: %d\nDescription: %s\n", &ec, res.Description)
			continue
		}
		if bot.MainListener == nil {
			bot.StartMainListener()
		}
		botsmap[tokenpath] = bot
	}

	pathtolisten := path.Join(pathl, "(?P<token>[a-zA-Z0-9-_]+)")

	m := martini.Classic()
	m.Post(pathtolisten, binding.Json(MessageWithUpdateID{}), func(params martini.Params, msg MessageWithUpdateID) {
		bot, ok := botsmap[params["token"]]

		if ok && msg.UpdateID > 0 && msg.Msg.ID > 0 {
			bot.MainListener <- msg
		} else {
			fmt.Println("Someone tried with: ", params["token"], msg)
		}
	})

	if newrelic != nil {
		gorelic.InitNewrelicAgent(newrelic.Token, newrelic.Name, false)
		m.Use(gorelic.Handler)
	}

	if host == "" || port == "" {
		m.Run()
	} else {
		m.RunOnAddr(host + ":" + port)
	}
}
예제 #4
0
func Initialize(m *martini.ClassicMartini) {
	fmt.Println("Running in production environment")

	newRelicLicenseKey := os.Getenv("NEW_RELIC_LICENSE_KEY")
	if len(newRelicLicenseKey) > 0 {
		gorelic.InitNewrelicAgent(newRelicLicenseKey, AppName, true)
		m.Use(gorelic.Handler)
	}
}
예제 #5
0
func (bot *TgBot) ServerStartHostPort(uri string, pathl string, host string, port string) {
	if bot.DefaultOptions.RecoverPanic {
		defer func() {
			if r := recover(); r != nil {
				fmt.Printf("There was some panic: %s\n", r)
			}
		}()
	}
	tokendiv := strings.Split(bot.Token, ":")
	if len(tokendiv) != 2 {
		return
	}
	pathl = path.Join(pathl, fmt.Sprintf("%s%s", tokendiv[0], tokendiv[1]))

	if uri != "" {
		puri, err := url.Parse(uri)
		if err != nil {
			fmt.Printf("Bad URL %s", uri)
			return
		}
		nuri, _ := puri.Parse(pathl)

		res, error := bot.SetWebhook(nuri.String())
		if error != nil {
			ec := res.ErrorCode
			fmt.Printf("Error setting the webhook: \nError code: %d\nDescription: %s\n", &ec, res.Description)
			return
		}
	}

	if bot.MainListener == nil {
		bot.StartMainListener()
	}

	m := martini.Classic()
	m.Post(pathl, binding.Json(MessageWithUpdateID{}), func(params martini.Params, msg MessageWithUpdateID) {
		if msg.UpdateID > 0 && msg.Msg.ID > 0 {
			bot.HandleBotan(msg.Msg)
			bot.MainListener <- msg
		}
	})

	if bot.RelicCfg != nil {
		gorelic.InitNewrelicAgent(bot.RelicCfg.Token, bot.RelicCfg.Name, false)
		m.Use(gorelic.Handler)
	}
	if host == "" || port == "" {
		m.Run()
	} else {
		m.RunOnAddr(host + ":" + port)
	}
}
예제 #6
0
파일: middleware.go 프로젝트: Bowbaq/bikage
func new_relic_handler(env Env) martini.Handler {
	gorelic.InitNewrelicAgent(env["NEW_RELIC_LICENSE_KEY"], env["NEW_RELIC_APP_NAME"], false)
	return gorelic.Handler
}