Skip to content

Commit

Permalink
Merge pull request #4 from dinhquang111/test
Browse files Browse the repository at this point in the history
aaa
  • Loading branch information
dinhquang111 authored Aug 29, 2024
2 parents 09912f1 + 9dde03f commit 52fd1d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
"program": "${workspaceFolder}"
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main ./
RUN go build -ldflags "-X main.Version=1.0.0 -X main.Commit=$(git rev-parse HEAD) -X main.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" -o main ./

FROM alpine:latest
WORKDIR /app
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ merge:
gh pr create --base $$targetBranch; \
"

docker-build:
docker-run:
@echo "Building the Docker image..."
docker build -t $(DOCKER_REPO):$(VERSION) .

docker-run:
docker run -d -p ${PORT}:${PORT} --name ${APP_NAME} $(DOCKER_REPO):$(VERSION)

docker-push: docker-build
Expand Down
33 changes: 20 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"log"
"net/http"
"strconv"
"strings"

"github.com/elastic/go-elasticsearch/v8"
Expand Down Expand Up @@ -155,20 +154,28 @@ func handleSearch(es *elasticsearch.Client) gin.HandlerFunc {
}
}

var (
Version = "dev"
Commit = "none"
BuildTime = "unknown"
)

func HealthCheckHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"version": Version,
"commit": Commit,
"buildTime": BuildTime,
})
}

func main() {
var elasticSearchHost = readConsulConfig()
esClient := connectElasticSearch(elasticSearchHost)
fmt.Println(esClient)
// var elasticSearchHost = readConsulConfig()
// esClient := connectElasticSearch(elasticSearchHost)
// fmt.Println(esClient)
router := gin.Default()
version := 4
router.GET("/ping/:name", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong " + c.Params.ByName("name"),
"version": "v" + strconv.Itoa(version),
})
})
router.GET("/health", HealthCheckHandler)

router.POST("/search", insertSearch(esClient))
router.GET("/search", handleSearch(esClient))
// router.POST("/search", insertSearch(esClient))
// router.GET("/search", handleSearch(esClient))
router.Run(":8080")
}

0 comments on commit 52fd1d9

Please sign in to comment.