-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerConfigModule.kt
36 lines (31 loc) · 1.44 KB
/
ServerConfigModule.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.samuelagesilas.nbafinals.modules
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.inject.AbstractModule
import com.google.inject.Provides
import com.google.inject.Singleton
import java.io.File
class ServerConfigModule constructor(private val configFileLocation: String) : AbstractModule() {
@Provides
@Singleton
fun provides(objectMapper: ObjectMapper): ServerConfig {
val configFileContent: String = File(configFileLocation).readText()
val typeReference: TypeReference<ServerConfig> = object : TypeReference<ServerConfig>() {}
return objectMapper.readValue<ServerConfig>(configFileContent, typeReference)
}
}
data class ServerConfig(val port: Int,
val mySqlConfig: MySqlConfig,
val dbPort: Int,
val dbHost: String,
val dbUsername: String,
val dbPassword: String,
val useDatabase: String,
val jwtKey: String,
val jwt_expiration_time_seconds: Int,
val redisHost: String,
val redisPort: Int,
val shutdownTimeoutSeconds: Long)
data class MySqlConfig(val cachePrepStmts: Boolean,
val verifyServerCertificate: Boolean,
val useSSL: Boolean)