Exemplo n.º 1
0
// https://github.com/astaxie/build-web-application-with-golang/blob/master/en/preface.md
func init() {
	// https://github.com/astaxie/beego/blob/master/session/session.go

	// globalSessions, _ = session.NewManager("redis", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:6379,100,astaxie"}`)

	// globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	// secure means force https
	f, err := os.Open("config.json")
	defer f.Close()

	checkError(err, "cannot load log file")

	// https://github.com/creamdog/gonfig
	config, err := gonfig.FromJson(f)
	checkError(err, "Could not parse config from file")
	cfg := make(map[string]interface{})
	err = config.GetAs("credentials/redis_session", &cfg)
	checkError(err, "could not read redis_session configuration")
	fmt.Printf("config is %v\n", cfg)
	s, err := json.Marshal(cfg)
	checkError(err, fmt.Sprintf("Error marshaling struct %v", cfg))
	GlobalSessions, err = session.NewManager("redis", string(s))
	checkError(err, "Error Establishing Redis Session")
	go GlobalSessions.GC()
}
Exemplo n.º 2
0
func init() {
	log.Println("Configuring Models.")
	// user, password, dbname, host := "stxuser", "37286d83-1ac0-11e2-bcf9-080027056e08", "qa", "localhost:3306"

	// go initMySQL()
	f, err := os.Open("config.json")
	if err != nil {
		log.Println("cannot find log file.", err)
		// TODO: error handling
	}
	defer f.Close()
	// https://github.com/creamdog/gonfig
	config, err = gonfig.FromJson(f)
	if err != nil {
		log.Println("could not load config file", err)
		// TODO: error handling
	}

	go initMongo()
	go initRedis()
}
Exemplo n.º 3
0
func interpretar(comando string) (bool, string) {

	var str string
	arrcadenas := strings.Split(comando, " ")
	// fmt.Printf("%s\n", arrcadenas)

	//Comandos
	f, err := os.Open("C:\\desarrollo\\ws_go\\src\\github.com\\gophergala2016\\FriendzoneTeam\\util\\performer\\comandos.json")
	if err != nil {
		fmt.Printf("Error abrir archivo: %s\n", err)
	}
	defer f.Close()

	dicc, err := gonfig.FromJson(f)

	if err != nil {
		fmt.Printf("Error abrir archivo: %s\n", err)
	}

	switch {
	case arrcadenas[0] == "create":
		str = create(dicc, arrcadenas)
	case arrcadenas[0] == "delete":
		str = delete(dicc, arrcadenas)
	case arrcadenas[0] == "move":
		str = move(dicc, arrcadenas)
	case arrcadenas[0] == "rename":
		str = rename(dicc, arrcadenas)
	case arrcadenas[0] == "server":
		str = server(dicc, arrcadenas)
	case strings.HasPrefix(arrcadenas[0], ":"):
		str = custom(arrcadenas)
	}

	if str != "" {
		return true, str
	}
	return false, "Comando Invalido"
}