Beispiel #1
0
func init() {
	deferinit.AddInit(func() {
		githubProvider = providers.NewGitHubProvider(&providers.ProviderData{
			LoginUrl:     &url.URL{},
			RedeemUrl:    &url.URL{},
			ProfileUrl:   &url.URL{},
			ValidateUrl:  &url.URL{},
			ClientID:     config.GetStringDefault("clientId", "66a252c0d27dc279b7cb"),
			ClientSecret: config.GetStringDefault("clientSecret", "a313e648feff0e6b30794142ff9304e42cd50da1"),
		})
		_sid = config.GetStringDefault("cookieName", "sid")
		_cookieSecure = config.GetBooleanDefault("cookieSecure", false)
		_cookieSeed = config.GetStringDefault("cookieSeed", "cookieseed")
		_expireSecond = config.GetIntDefault("cookieExpire", 86400*30)
		_cookieExpire = time.Duration(_expireSecond) * time.Second
	}, nil, 0)
}
Beispiel #2
0
func setGlobalVars() {
	domain = strings.TrimSpace(config.GetStringDefault("domain", "http://127.0.0.1"))
	if domain[len(domain)-1] == '/' {
		domain = domain[0 : len(domain)-1]
	}

	port = config.GetIntDefault("port", 80)
	if port != 80 {
		hostname = fmt.Sprintf("%s:%d", domain, port)
	} else {
		hostname = domain
	}
}
Beispiel #3
0
// 建立数据库连接
func opendb(dbname, dbuser, dbpass string) (*gorm.DB, error) {
	var (
		dbtype, dsn string
		db          gorm.DB
		err         error
	)

	if dbuser == "" {
		dbuser = config.GetStringDefault("dbuser", "root")
	}
	if dbpass == "" {
		dbpass = config.GetStringDefault("dbpass", "root")
	}

	dbtype = strings.ToLower(config.GetStringDefault("dbtype", "mysql"))
	if dbtype == "mysql" {
		dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
			dbuser,
			dbpass,
			config.GetStringDefault("dbproto", "tcp"),
			config.GetStringDefault("dbhost", "localhost"),
			config.GetIntDefault("dbport", 3306),
			dbname,
		)
	} else if dbtype == "pg" || dbtype == "postgres" || dbtype == "postgresql" {
		dbtype = "postgres"
		dsn = fmt.Sprintf("user=%s password=%s host=%s port=%d dbname=%s sslmode=disable",
			dbuser,
			dbpass,
			config.GetStringDefault("dbhost", "127.0.0.1"),
			config.GetIntDefault("dbport", 5432),
			dbname)
	}

	db, err = gorm.Open(dbtype, dsn)
	if err != nil {
		log.Println(err.Error())
		return &db, err
	}

	err = db.DB().Ping()
	if err != nil {
		log.Println(err.Error())
		return &db, err
	}

	return &db, nil
}