-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from codescalersinternships/development
datetime Server
- Loading branch information
Showing
21 changed files
with
831 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Go CI | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.23.1' | ||
- name: Build | ||
run: go build -v ./... | ||
|
||
|
||
golangci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.60 | ||
- name: Go Format | ||
uses: Jerome1337/[email protected] | ||
with: | ||
gofmt-path: './src' | ||
gofmt-flags: '-l -d' | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- name: Test http server | ||
run: go test -v ./pkg/httpserver | ||
- name: Test gin server | ||
run: go test -v ./pkg/ginserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:latest AS builder | ||
|
||
WORKDIR /build | ||
|
||
COPY . . | ||
|
||
RUN go mod download | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o ginout ./cmd/ginserver/main.go | ||
|
||
EXPOSE 8083 | ||
|
||
FROM scratch | ||
WORKDIR /app | ||
COPY --from=builder /build/ginout . | ||
|
||
ENTRYPOINT [ "/app/ginout" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:latest AS builder | ||
|
||
WORKDIR /build | ||
|
||
COPY . . | ||
|
||
RUN go mod download | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o httpout ./cmd/httpserver/main.go | ||
|
||
EXPOSE 8080 | ||
|
||
FROM scratch | ||
WORKDIR /app | ||
COPY --from=builder /build/httpout . | ||
|
||
ENTRYPOINT [ "/app/httpout" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
build: | ||
go build -o httpout ./cmd/httpserver/main.go | ||
go build -o ginout ./cmd/ginserver/main.go | ||
|
||
format: | ||
go fmt ./... | ||
|
||
lint: | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
golangci-lint run ./... | ||
|
||
build-run-Images: | ||
docker-compose up | ||
|
||
all: build format lint build-run-Images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,55 @@ | ||
# Date-time-server-RawanMostafa | ||
# Datetime Server | ||
|
||
This repository implements http and Gin datetime servers. | ||
|
||
## Table of Contents | ||
|
||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
|
||
|
||
## Installation | ||
|
||
1. Clone the repository | ||
|
||
```bash | ||
git clone https://github.com/codescalersinternships/Datetime-server-RawanMostafa.git | ||
``` | ||
|
||
2. Install the dependencies | ||
```bash | ||
go mod download | ||
``` | ||
|
||
## Usage | ||
|
||
### 1. Using Makefile | ||
|
||
To run all make targets | ||
|
||
```bash | ||
make all | ||
``` | ||
|
||
### 2. Using docker-compose | ||
|
||
|
||
```bash | ||
docker-compose up | ||
``` | ||
|
||
### 2. Using kubernetes deployed server | ||
|
||
|
||
```bash | ||
curl http://185.206.122.17:30100/ | ||
``` | ||
|
||
### 3. Using main.go | ||
|
||
```bash | ||
go run cmd/httpserver/main.go | ||
``` | ||
```bash | ||
go run cmd/ginserver/main.go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
ginhandler "github.com/codescalersinternships/Datetime-server-RawanMostafa/pkg/ginserver" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
const defaultPort = "8083" | ||
|
||
func getFlags() string { | ||
var port string | ||
flag.StringVar(&port, "port", "", "Specifies the port") | ||
|
||
flag.Parse() | ||
return port | ||
} | ||
|
||
func decideConfigs() string { | ||
|
||
port := getFlags() | ||
|
||
if port == "" { | ||
envPort, found := os.LookupEnv("DATETIME_PORT") | ||
|
||
if found { | ||
port = envPort | ||
} else { | ||
port = defaultPort | ||
} | ||
} | ||
return port | ||
|
||
} | ||
func main() { | ||
port := decideConfigs() | ||
r := gin.Default() | ||
r.GET("/", ginhandler.GinHome) | ||
r.GET("/datetime", ginhandler.GinHandler) | ||
err := r.Run(fmt.Sprintf(":%s", port)) | ||
if err != nil { | ||
log.Fatalf("Error: impossible to start server: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
|
||
httphandler "github.com/codescalersinternships/Datetime-server-RawanMostafa/pkg/httpserver" | ||
) | ||
|
||
const defaultPort = "8083" | ||
|
||
func getFlags() string { | ||
var port string | ||
flag.StringVar(&port, "port", "", "Specifies the port") | ||
|
||
flag.Parse() | ||
return port | ||
} | ||
|
||
func decideConfigs() string { | ||
|
||
port := getFlags() | ||
|
||
if port == "" { | ||
envPort, found := os.LookupEnv("DATETIME_PORT") | ||
|
||
if found { | ||
port = envPort | ||
} else { | ||
port = defaultPort | ||
} | ||
} | ||
return port | ||
|
||
} | ||
func main() { | ||
port := decideConfigs() | ||
|
||
fmt.Println("Starting our simple http server.") | ||
|
||
http.HandleFunc("/", httphandler.HttpHome) | ||
http.HandleFunc("/datetime", httphandler.HttpHandler) | ||
|
||
fmt.Printf("Started on port :%s\n", port) | ||
|
||
err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: v2 | ||
name: datetime-server | ||
description: A Helm chart for Kubernetes | ||
|
||
# A chart can be either an 'application' or a 'library' chart. | ||
# | ||
# Application charts are a collection of templates that can be packaged into versioned archives | ||
# to be deployed. | ||
# | ||
# Library charts provide useful utilities or functions for the chart developer. They're included as | ||
# a dependency of application charts to inject those utilities and functions into the rendering | ||
# pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
type: application | ||
|
||
# This is the chart version. This version number should be incremented each time you make changes | ||
# to the chart and its templates, including the app version. | ||
# Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
version: 0.1.0 | ||
|
||
# This is the version number of the application being deployed. This version number should be | ||
# incremented each time you make changes to the application. Versions are not expected to | ||
# follow Semantic Versioning. They should reflect the version the application is using. | ||
# It is recommended to use it with quotes. | ||
appVersion: "1.16.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: gin-deployment | ||
labels: | ||
app: {{ .Values.ginAppName }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: {{ .Values.ginAppName }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ .Values.ginAppName }} | ||
spec: | ||
containers: | ||
- name: {{ .Values.ginAppName }} | ||
image: "{{ .Values.ginImage.name }}:{{ .Values.ginImage.tag }}" | ||
ports: | ||
- containerPort: 8083 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: gin-service | ||
spec: | ||
type: NodePort | ||
selector: | ||
app: {{ .Values.ginAppName }} | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 8083 | ||
nodePort: 30500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: http-deployment | ||
labels: | ||
app: {{ .Values.httpAppName }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: {{ .Values.httpAppName }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ .Values.httpAppName }} | ||
spec: | ||
containers: | ||
- name: {{ .Values.httpAppName }} | ||
image: "{{ .Values.httpImage.name }}:{{ .Values.httpImage.tag }}" | ||
ports: | ||
- containerPort: 8080 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: http-service | ||
spec: | ||
type: NodePort | ||
selector: | ||
app: {{ .Values.httpAppName }} | ||
ports: | ||
- protocol: TCP | ||
port: 8083 | ||
targetPort: 8080 | ||
nodePort: 30400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ginAppName: gin-server | ||
httpAppName: http-server | ||
|
||
ginImage: | ||
name: rawanmostafa/ginserver | ||
tag: latest | ||
|
||
httpImage: | ||
name: rawanmostafa/httpserver | ||
tag: latest |
Oops, something went wrong.