사실 우리의 첫 선택은..
React + SpringBoot
Java Keyword : 50
Go Keyword : 25
Duck Typing
만약 어떤 새가 오리처럼 걷고,
헤엄치고, 꽥꽥거리는 소리를 낸다면
나는 그 새를 오리라고 부를 것이다.
#### Java Rest API
```java
@RestController
public class HelloController {
@Autowired
private HelloService service;
@GetMapping(value = "/hello")
public String sayHello() {
return "Hello" + service.getName();
}
@PostMapping(value = "/hello/{name}")
public Hello hello(@PathVariable(value = "name") String name) {
return service.saveHello(name);
}
}
```
#### Go Rest API
```go
import (
"github.com/gorilla/mux"
"encoding/json"
"net/http"
)
func InitRouting(r *mux.Router) {
r.HandleFunc("/entities", GetHandler).Methods("GET")
}
type HelloHandler struct {
service Service
}
func (h *HelloHandler) GetHandler(w http.ResponseWriter, r *http.Request) {
name := h.service.GetName()
w.Header().Set("Content-Type", "application/json")
j, _ := json.Marshal("Hello " + name)
w.Write(j)
}
```
#### Java Rest API Test
```java
@RunWith(SpringRunner.class)
@WebMvcTest(HelloController.class)
public class HelloRestControllerTest {
@Autowired MockMvc mvc;
@MockBean HelloService serviceMock;
@Test
public void whenCallHelloApi_thenReturnHelloMessage() throws Exception {
given(serviceMock.getName()).willReturn("Kihoon");
mvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string("Hello Kihoon"));
}
}
```
#### Go Rest API Test
```go
func TestHelloHandler_GetHandler(t *testing.T) {
ctrl := gomock.NewController(t)
mockService := NewMockService(ctrl)
mockService.EXPECT().GetName().Return("Kihoon")
handler := HelloHandler{mockService}
req, _ := http.NewRequest("GET", "/hello", nil)
recorder := executeRouter(handler, req)
assert.Equal(t, "Hello Kihoon", recorder.Body.String())
}
```
프로그래밍 언어 순위
https://www.tiobe.com/tiobe-index/