Skip to content

Commit

Permalink
tes
Browse files Browse the repository at this point in the history
  • Loading branch information
Quang nd committed Oct 1, 2024
1 parent a3463aa commit d819744
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 98 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
# 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 ./
RUN go build -o main ./cmd/api
RUN go build -o main ./cmd/api/main.go

FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/main .
EXPOSE 8080
CMD ["./main"]
ENV GIN_MODE=release
CMD ["./main"]
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
APP_NAME := basic-go-service
DOCKER_USERNAME := darthmalgus1997
DOCKER_REPO := $(DOCKER_USERNAME)/$(APP_NAME)
VERSION := 1.0.0
VERSION := 1.0.6
PORT := 8080
OUTPUT_FILE= bin/main.exe

Expand Down Expand Up @@ -56,6 +56,4 @@ docker-rm-container:
docker rm ${APP_NAME}

swag:
swag init -g cmd/api/main.go


swag init -g cmd/api/main.go
14 changes: 8 additions & 6 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ import (
"basic-go/internal/jenkins"
"basic-go/internal/logger"
"basic-go/internal/middleware"

"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)

// @title Service API
// @version 1.0

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @contact.email support@swagger.ioT

// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization

// @host localhost:8080
// @host localhost:8080
// @BasePath /

func main() {
gin.SetMode(gin.ReleaseMode)
jenkins.SetupJenkin()
jenkins.SetupJenkins()
logger.SetupLogger()
engine := gin.New()
engine.Use(middleware.Logger())
engine.Use(middleware.ErrorHandler())
routes.SetupRoutes(engine)
engine.Run(":8080")
err := engine.Run(":8080")
if err != nil {
log.Fatal().Msg("Failed to start server")
}
}
11 changes: 1 addition & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ require (
github.com/google/uuid v1.6.0
github.com/rabbitmq/amqp091-go v1.10.0
github.com/rs/zerolog v1.33.0
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
Expand All @@ -46,14 +44,9 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/urfave/cli/v2 v2.27.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
Expand All @@ -64,7 +57,5 @@ require (
golang.org/x/text v0.18.0 // indirect
golang.org/x/tools v0.25.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
70 changes: 8 additions & 62 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/api/handlers/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Query(c *gin.Context) {

// Extract hits from the response
hits := response["hits"].(map[string]interface{})["hits"].([]interface{})
results := []map[string]interface{}{}
var results []map[string]interface{}

for _, hit := range hits {
doc := hit.(map[string]interface{})["_source"].(map[string]interface{})
Expand Down
6 changes: 3 additions & 3 deletions internal/api/handlers/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ type RequestMessage struct {
}

func ValidateJenkinsJob() {
job, err := jenkins.JenkinClient.GetJob(jenkins.JenkinCtx, "Backend", "CLS", "Staging")
job, err := jenkins.Client.GetJob(jenkins.Ctx, "Backend", "CLS", "Staging")
if err != nil {
panic(err)
}
details, _ := job.GetParameters(jenkins.JenkinCtx)
isBuilding, _ := job.IsRunning(jenkins.JenkinCtx)
details, _ := job.GetParameters(jenkins.Ctx)
isBuilding, _ := job.IsRunning(jenkins.Ctx)
fmt.Print(details, isBuilding)
}

Expand Down
7 changes: 3 additions & 4 deletions internal/controller/health.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package controller

import (
"net/http"

"github.com/gin-gonic/gin"
"net/http"
)

var (
Expand All @@ -12,7 +11,7 @@ var (
BuildTime = "unknown"
)

// @Summary Health check application
// HealthCheck @Summary Health check application
// @Description Health check and return app's metadata
// @Produce json
// @Success 200 {object} string
Expand All @@ -25,7 +24,7 @@ func (c *Controller) HealthCheck(ctx *gin.Context) {
})
}

// @Summary Health check application
// HealthCheck1 @Summary Health check application
// @Description Health check and return app's metadata
// @Produce json
// @Success 200 {object} string
Expand Down
14 changes: 8 additions & 6 deletions internal/jenkins/jennkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package jenkins

import (
"context"
"github.com/rs/zerolog/log"

"github.com/bndr/gojenkins"
)

var JenkinCtx context.Context
var JenkinClient *gojenkins.Jenkins
var Ctx context.Context
var Client *gojenkins.Jenkins
var defaultBranch = "dev"

func SetupJenkin() {
JenkinCtx = context.Background()
JenkinClient := gojenkins.CreateJenkins(nil, "http://113.160.247.103:9000", "nhatcx", "111fc9efe79685c067f923bf3d2ce8545e")
_, err := JenkinClient.Init(JenkinCtx)
func SetupJenkins() {
Ctx = context.Background()
JenkinsClient := gojenkins.CreateJenkins(nil, "http://113.160.247.103:9000", "nhatcx", "111fc9efe79685c067f923bf3d2ce8545e")
_, err := JenkinsClient.Init(Ctx)
if err != nil {
log.Fatal().Msg("Failed to init Jenkins client")
panic("Invalid jenkins client")
}
}

0 comments on commit d819744

Please sign in to comment.