refactor: rename examples/ directory to lib/ and update all path references

This commit is contained in:
2026-07-17 19:21:21 +09:00
parent 8f183d597e
commit 8bb11fe205
17 changed files with 49 additions and 49 deletions
+25
View File
@@ -0,0 +1,25 @@
# lib/httpentity 실습 설명서
본 디렉토리는 Go 언어 웹 프레임워크인 Gin(`gin-gonic`)을 활용한 HTTP 웹 API 서버 실습 예제를 포함하고 있습니다.
## 📖 실습 상세 분석 및 가이드 안내
이 실습에 대한 상세한 코드 구조 설명과 Gin 라우터 설계 이론은 심화 학습 문서인 **[docs/HTTP.md](../../docs/HTTP.md)**에서 상세히 기술되어 있습니다.
[docs/HTTP.md](../../docs/HTTP.md) 문서에서 다음 내용을 공부할 수 있습니다:
* **HTTP 프로토콜 및 REST API 기본 구조**
* **Gin 웹 프레임워크의 라우터 매핑 (`gin.Default()` vs `gin.New()`)**
* **API 라우터와 정적 웹 리소스 서빙 우회 설계 패턴**
---
## 🚀 빠른 실행 방법
이 예제는 리포지토리 루트의 `lib/main.go`를 통해 실행됩니다.
1. 리포지토리 루트 of `lib/main.go`를 엽니다.
2. `main()` 함수 내에서 `httpentity` API 호출 주석을 해제합니다. (현재 주석 상태로, 추후 구현 완성을 위한 예제 뼈대 파일입니다.)
3. 리포지토리 루트에서 다음 명령어를 실행합니다:
```bash
go run ./lib
```
+1
View File
@@ -0,0 +1 @@
package httpentity
+83
View File
@@ -0,0 +1,83 @@
package httpentity
// import (
// "encoding/json"
// "log"
// "net/http"
// "strings"
// "github.com/gin-gonic/gin"
// )
// func NewWebServer(addr string) *http.Server {
// srv := &http.Server{
// Addr: addr,
// Handler: createRouter(),
// }
// return srv
// }
// func createRouter() *gin.Engine {
// // Create a new gin router for api
// // What is difference between gin.Default() and gin.New()?
// // https://stackoverflow.com/questions/44318441/what-is-difference-between-gin-default-and-gin-new
// apiEngine := gin.New()
// apiGroup := apiEngine.Group("/api")
// {
// apiGroup.GET("/randomNumber", GET_RandomNumber)
// apiGroup.GET("/randomPassword", GET_RandomPassword)
// apiGroup.GET("/randomDate", GET_RandomDate)
// }
// // create a new gin router for static files
// staticEngine := gin.New()
// staticEngine.Static("/", "./web")
// // Create a new gin router
// r := gin.Default()
// // r can accept all messages from apiEngine and staticEngine
// r.Any("/*any", func(c *gin.Context) {
// defer handleError(c)
// w := c.Writer
// w.Header().Set("Access-Control-Allow-Origin", "*")
// w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
// path := c.Param("any")
// if strings.HasPrefix(path, "/api") {
// apiEngine.ServeHTTP(c.Writer, c.Request)
// } else {
// staticEngine.HandleContext(c)
// }
// })
// // Return the router
// return r
// }
// func GET_RandomNumber(c *gin.Context) {
// // make a json decoder
// dec := json.NewDecoder(c.Request.Body)
// obj := map[string]interface{}{}
// dec.Decode(&obj)
// seed := obj["seed"]
// place := obj["place"]
// response := map[string]interface{}{
// "value": 10,
// }
// c.JSON(http.StatusOK)
// }
// func handleError(c *gin.Context) {
// if r := recover(); r != nil {
// log.Println(r)
// c.String(http.StatusBadRequest, r.(error).Error())
// }
// }