Skip to content

Commit ea8757b

Browse files
feat: read configs from config toml file
1 parent efa9c18 commit ea8757b

8 files changed

Lines changed: 85 additions & 16 deletions

File tree

.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
</properties>
3232

3333
<dependencies>
34+
<dependency>
35+
<groupId>com.moandjiezana.toml</groupId>
36+
<artifactId>toml4j</artifactId>
37+
<version>0.7.2</version>
38+
</dependency>
3439
<!-- Application dependencies -->
3540
<dependency>
3641
<groupId>org.springframework.boot</groupId>
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
package uz.server;
22

3+
import com.moandjiezana.toml.Toml;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56

7+
import java.io.File;
8+
import java.util.Arrays;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
612
@SpringBootApplication
713
public class ServerApplication {
814
public static void main(String[] args) {
9-
SpringApplication.run(ServerApplication.class, args);
15+
String path = Arrays.stream(args).filter(s -> s.startsWith("--config=")).findFirst().orElseThrow(
16+
() -> new RuntimeException("Config path not provided")
17+
);
18+
19+
Map<String, Object> props = loadToml(path);
20+
21+
SpringApplication app = new SpringApplication(ServerApplication.class);
22+
app.setDefaultProperties(props);
23+
app.run(args);
24+
}
25+
26+
public static Map<String, Object> loadToml(String path){
27+
Toml toml = new Toml().read(new File(path));
28+
Map<String, Object> map = new HashMap<>();
29+
map.put("spring.datasource.url", toml.getString("spring.datasource.url"));
30+
map.put("spring.datasource.username", toml.getString("spring.datasource.username"));
31+
map.put("spring.datasource.password", toml.getString("spring.datasource.password"));
32+
map.put("github.client-id", toml.getString("github.client-id"));
33+
map.put("github.client-secret", toml.getString("github.client-secret"));
34+
map.put("github.redirect-uri", toml.getString("github.redirect-uri"));
35+
return map;
1036
}
1137
}

server/src/main/resources/application.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ spring:
22
application:
33
name: server
44
datasource:
5-
url: "${SPRING_DATASOURCE_URL}"
6-
username: "${SPRING_DATASOURCE_USERNAME}"
7-
password: "${SPRING_DATASOURCE_PASSWORD}"
8-
driver-class-name: "org.postgresql.Driver"
5+
url: ${spring.datasource.url}
6+
username: ${spring.datasource.username}
7+
password: ${spring.datasource.password}
8+
driver-class-name: org.postgresql.Driver
99
servlet:
1010
multipart:
1111
max-file-size: 100MB
@@ -24,9 +24,9 @@ server:
2424
max-swallow-size: 100MB
2525

2626
github:
27-
client-id: "${GITHUB_CLIENT_ID}"
28-
client-secret: "${GITHUB_CLIENT_SECRET}"
29-
redirect-uri: "${GITHUB_REDIRECT_URI}"
27+
client-id: "${github.client-id}"
28+
client-secret: "${github.client-secret}"
29+
redirect-uri: "${github.redirect-uri}"
3030
management:
3131
endpoint:
3232
health:

0 commit comments

Comments
 (0)