commit 35a119b3b37ec9c511646b367c65aabbd9cd4b7c Author: Aditya Prima Date: Tue Mar 12 14:27:28 2024 +0700 Initial Commit diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..45d0536 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,15 @@ +image: docker:24.0.5 + +before_script: + - "docker login ${CI_REGISTRY} -u gitlab-ci-token -p ${CI_JOB_TOKEN}" +after_script: + - "docker logout ${CI_REGISTRY}" + +stages: + - build + +build: + stage: build + script: + - DOCKER_BUILDKIT=1 docker image build -f ./docker/Dockerfile -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest . + - docker image push ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..b0b9f4f --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,32 @@ +############################ +# STEP 1 build executable binary +############################ +FROM golang:alpine AS builder + +# Install git. +# Git is required for fetching the dependencies. +RUN apk update && apk add --no-cache git + +WORKDIR $GOPATH/src/mypackage/myapp/ + +COPY . . + +# Fetch dependencies. +# Using go get. +RUN go get -d -v + +# Build the binary. +RUN go build -o /go/bin/server + +############################ +# STEP 2 build a small image +############################ +FROM scratch + +# Copy our static executable. +COPY --from=builder /go/bin/server /go/bin/server + +# Run the hello binary. +ENTRYPOINT ["/go/bin/server"] + +EXPOSE 3000 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5a06efb --- /dev/null +++ b/go.mod @@ -0,0 +1,18 @@ +module golang-echo + +go 1.21.0 + +require ( + github.com/andybalholm/brotli v1.0.5 // indirect + github.com/gofiber/fiber/v2 v2.52.2 // indirect + github.com/google/uuid v1.5.0 // indirect + github.com/klauspost/compress v1.17.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/rivo/uniseg v0.2.0 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasthttp v1.51.0 // indirect + github.com/valyala/tcplisten v1.0.0 // indirect + golang.org/x/sys v0.15.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..6b417f9 --- /dev/null +++ b/go.sum @@ -0,0 +1,27 @@ +github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= +github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/gofiber/fiber/v2 v2.52.2 h1:b0rYH6b06Df+4NyrbdptQL8ifuxw/Tf2DgfkZkDaxEo= +github.com/gofiber/fiber/v2 v2.52.2/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= +github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= +github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA= +github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g= +github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= +github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/server.go b/server.go new file mode 100644 index 0000000..10ecf39 --- /dev/null +++ b/server.go @@ -0,0 +1,46 @@ +package main + +import ( + "log" + + "github.com/gofiber/fiber/v2" +) + +type TestInfo struct { + Id int `json:"id"` + Name string `json:"name"` +} + +func main() { + app := fiber.New() + + app.Get("/", func(c *fiber.Ctx) error { + + a := TestInfo{ + Id: 1, + Name: "testing", + } + + var tester []TestInfo + + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + tester = append(tester, a) + + return c.Status(200).JSON(tester) + }) + + log.Fatal(app.Listen(":3000")) +}