Просмотр исходного кода

Refactor: meaningful index response

wudi 5 лет назад
Родитель
Сommit
2ddef87698

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
 	</parent>
 	<groupId>com.mokasz</groupId>
 	<artifactId>image-pool</artifactId>
-	<version>1.0.0</version>
+	<version>1.0.1</version>
 	<name>image-pool</name>
 	<description>Image Pool Matching Service</description>
 	<properties>

+ 17 - 2
src/main/java/com/mokasz/image_pool/restful/controller/IndexController.java

@@ -1,14 +1,29 @@
 package com.mokasz.image_pool.restful.controller;
 
+import com.mokasz.image_pool.restful.entity.IndexResponse;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 @RestController
 @RequiredArgsConstructor
 public class IndexController {
+    @Value("${pom.version}")
+    private String version;
+
+    private String getHostname () {
+        try {
+            return InetAddress.getLocalHost().getHostName();
+        } catch (UnknownHostException e) {
+            return "x";
+        }
+    }
     @GetMapping("/")
-    public String index() {
-        return "version:1.0.0";
+    public IndexResponse index() {
+        return new IndexResponse(version, getHostname());
     }
 }

+ 9 - 0
src/main/java/com/mokasz/image_pool/restful/entity/IndexResponse.java

@@ -0,0 +1,9 @@
+package com.mokasz.image_pool.restful.entity;
+
+import lombok.Data;
+
+@Data
+public class IndexResponse {
+    private final String version;
+    private final String hostname;
+}

+ 1 - 0
src/main/resources/application.properties

@@ -1,5 +1,6 @@
 # app
 debug=false
+pom.version=@project.version@
 # db
 spring.datasource.driverClassName = org.postgresql.Driver
 spring.datasource.url = jdbc:postgresql://gp-uf61gv6sn7u6ij7kb-master.gpdbmaster.rds.aliyuncs.com:5432/wudi_test?useUnicode=true&useSSL=false