Use RedisUrl correctly. (#17)

This commit is contained in:
Naoki Kosaka 2019-03-16 14:36:03 +09:00 committed by GitHub
parent 553866cac0
commit 376ae5a099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 29 deletions

View File

@ -5,7 +5,7 @@ jobs:
docker:
- image: circleci/golang
environment:
REDIS_URL: localhost:6379
REDIS_URL: redis://localhost:6379/0
- image: redis:alpine
steps:
- checkout

View File

@ -12,9 +12,11 @@ var redisClient *redis.Client
func TestMain(m *testing.M) {
viper.BindEnv("redis_url")
redisClient = redis.NewClient(&redis.Options{
Addr: viper.GetString("redis_url"),
})
redisOption, err := redis.ParseURL(viper.GetString("redis_url"))
if err != nil {
panic(err)
}
redisClient = redis.NewClient(redisOption)
code := m.Run()
os.Exit(code)

View File

@ -24,16 +24,21 @@ func initConfig() {
viper.BindEnv("redis_url")
hostkey, _ = keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
hostname, _ = url.Parse("https://" + viper.GetString("relay_domain"))
redClient := redis.NewClient(&redis.Options{
Addr: viper.GetString("redis_url"),
})
redOption, err := redis.ParseURL(viper.GetString("redis_url"))
if err != nil {
panic(err)
}
redClient := redis.NewClient(redOption)
var macConfig = &config.Config{
Broker: "redis://" + viper.GetString("redis_url"),
Broker: viper.GetString("redis_url"),
DefaultQueue: "relay",
ResultBackend: "redis://" + viper.GetString("redis_url"),
ResultBackend: viper.GetString("redis_url"),
ResultsExpireIn: 5,
}
macServer, _ = machinery.NewServer(macConfig)
macServer, err = machinery.NewServer(macConfig)
if err != nil {
panic(err)
}
relayState = state.NewState(redClient)
}

View File

@ -8,8 +8,8 @@ import (
)
func TestMain(m *testing.M) {
viper.Set("Actor_pem", "misc/testKey.pem")
viper.Set("Relay_domain", "relay.yukimochi.example.org")
viper.Set("actor_pem", "misc/testKey.pem")
viper.Set("relay_domain", "relay.yukimochi.example.org")
initConfig()
relayState.RedisClient.FlushAll().Result()

17
main.go
View File

@ -37,16 +37,21 @@ func initConfig() {
viper.BindEnv("redis_url")
hostURL, _ = url.Parse("https://" + viper.GetString("relay_domain"))
hostPrivatekey, _ = keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
redisClient := redis.NewClient(&redis.Options{
Addr: viper.GetString("redis_url"),
})
redisOption, err := redis.ParseURL(viper.GetString("redis_url"))
if err != nil {
panic(err)
}
redisClient := redis.NewClient(redisOption)
machineryConfig := &config.Config{
Broker: "redis://" + viper.GetString("redis_url"),
Broker: viper.GetString("redis_url"),
DefaultQueue: "relay",
ResultBackend: "redis://" + viper.GetString("redis_url"),
ResultBackend: viper.GetString("redis_url"),
ResultsExpireIn: 5,
}
machineryServer, _ = machinery.NewServer(machineryConfig)
machineryServer, err = machinery.NewServer(machineryConfig)
if err != nil {
panic(err)
}
uaString = viper.GetString("relay_servicename") + " (golang net/http; Activity-Relay v0.2.2; " + hostURL.Host + ")"
relayState = state.NewState(redisClient)
actorCache = cache.New(5*time.Minute, 10*time.Minute)

View File

@ -8,8 +8,8 @@ import (
)
func TestMain(m *testing.M) {
viper.Set("Actor_pem", "misc/testKey.pem")
viper.Set("Relay_domain", "relay.yukimochi.example.org")
viper.Set("actor_pem", "misc/testKey.pem")
viper.Set("relay_domain", "relay.yukimochi.example.org")
initConfig()
// Load Config

View File

@ -28,7 +28,7 @@ See [GitHub wiki](https://github.com/yukimochi/Activity-Relay/wiki)
- `RELAY_DOMAIN` (ex. `relay.toot.yukimochi.jp`)
- `RELAY_SERVICENAME` (ex. `YUKIMOCHI Toot Relay Service`)
- `RELAY_BIND` (ex. `0.0.0.0:8080`)
- `REDIS_URL` (ex. `127.0.0.1:6379`)
- `REDIS_URL` (ex. `redis://127.0.0.1:6379/0`)
## License

View File

@ -54,16 +54,21 @@ func initConfig() {
viper.BindEnv("redis_url")
hostURL, _ = url.Parse("https://" + viper.GetString("relay_domain"))
hostPrivatekey, _ = keyloader.ReadPrivateKeyRSAfromPath(viper.GetString("actor_pem"))
redisClient = redis.NewClient(&redis.Options{
Addr: viper.GetString("redis_url"),
})
redisOption, err := redis.ParseURL(viper.GetString("redis_url"))
if err != nil {
panic(err)
}
redisClient = redis.NewClient(redisOption)
machineryConfig := &config.Config{
Broker: "redis://" + viper.GetString("redis_url"),
Broker: viper.GetString("redis_url"),
DefaultQueue: "relay",
ResultBackend: "redis://" + viper.GetString("redis_url"),
ResultBackend: viper.GetString("redis_url"),
ResultsExpireIn: 5,
}
machineryServer, _ = machinery.NewServer(machineryConfig)
machineryServer, err = machinery.NewServer(machineryConfig)
if err != nil {
panic(err)
}
newNullLogger := NewNullLogger()
log.DEBUG = newNullLogger
uaString = viper.GetString("relay_servicename") + " (golang net/http; Activity-Relay v0.2.2; " + hostURL.Host + ")"

View File

@ -12,8 +12,8 @@ import (
)
func TestMain(m *testing.M) {
viper.Set("Actor_pem", "../misc/testKey.pem")
viper.Set("Relay_domain", "relay.yukimochi.example.org")
viper.Set("actor_pem", "../misc/testKey.pem")
viper.Set("relay_domain", "relay.yukimochi.example.org")
initConfig()
redisClient.FlushAll().Result()