Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init project #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.idea
.idea
.dev.env
deployment/postgres
bin
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
clear:
rm -rf ./bin
install:
brew install vault
build: clear
go build -o ./bin/ ./cmd/...
run: build
./bin/$(APP)
test: build
go test -v ./...
test-coverage: build
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
test-coverage-ci: build
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
lint: build
golangci-lint run --fast
docker-start:
docker-compose -f ./deployment/docker-compose.yml --env-file .dev.env up -d --build
docker-stop:
docker-compose -f ./deployment/docker-compose.yml --env-file .dev.env down
docker-ps:
docker-compose -f ./deployment/docker-compose.yml --env-file .dev.env ps
docker-logs:
docker-compose -f ./deployment/docker-compose.yml --env-file .dev.env logs -f --tail=100
68 changes: 0 additions & 68 deletions cmd/main.go

This file was deleted.

50 changes: 50 additions & 0 deletions cmd/userservice/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"github.com/gin-gonic/gin"
"github.com/go-turk/user-auth-service/internal/core/handlers"
"github.com/go-turk/user-auth-service/pkg/postgres"
"log"
"net/http"
)

// @title User Auth Service API
// @description This is a sample server for a user auth service.
// @version 0.1.0
func main() {
logger := log.New(log.Writer(), "user-auth-service", log.LstdFlags)
db, err := postgres.Connection()
if err != nil {
logger.Fatal(err)
}
logger.Printf("Connected to database: %s", db)
r := gin.Default()
healthChecker(r)
userHandler := handlers.NewUserHandler(r, logger)
if err := userHandler.Run(); err != nil {
logger.Fatal(err)
}
if err := r.Run(":8080"); err != nil {
logger.Fatal(err)
}
}

// @Summary Health Checker
// @Description Health Checker for User Auth Service
// @Accept json
// @Produce json
// @Success 200 {object} HealthCheckResponse
// @Router /healthcheck [get]

type HealthCheckResponse struct {
Status string `json:"status"`
}

func healthChecker(r *gin.Engine) {
r.GET("/healthcheck", func(c *gin.Context) {
responseForHealthCheck := HealthCheckResponse{
Status: "OK",
}
c.JSON(http.StatusOK, responseForHealthCheck)
})
}
32 changes: 32 additions & 0 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.7"

services:
userservice:
container_name: user_service
build:
context: ../
dockerfile: deployment/userservice/Dockerfile
ports:
- "80:8080"
restart: always
networks:
- userservice-network
environment:
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
postgres:
container_name: postgres
image: postgres:latest
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- ./postgres:/var/lib/postgresql/data
networks:
- userservice-network
networks:
userservice-network:
driver: bridge
13 changes: 13 additions & 0 deletions deployment/userservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.19-alpine

WORKDIR /adana

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN go build -o main /adana/cmd/userservice

CMD ["./main"]
117 changes: 17 additions & 100 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,122 +16,39 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/": {
"get": {
"description": "Hello World Description",
"tags": [
"User Service"
],
"summary": "Hello World",
"responses": {
"200": {
"description": "Hoş Geldin Dünyaya",
"schema": {
"type": "string"
}
},
"400": {
"description": "Hata",
"schema": {
"type": "string"
}
},
"500": {
"description": "Sunucu Hatası",
"schema": {
"type": "string"
}
},
"default": {
"description": "Bilinmeyen Hata",
"schema": {
"type": "string"
}
}
}
},
"/refresh-token": {
"post": {
"description": "User Post Description",
"description": "Refresh Token for User Auth Service",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"User Service"
],
"summary": "User Post",
"parameters": [
{
"description": "Username",
"name": "username",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Password",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"summary": "Refresh Token",
"responses": {
"200": {
"description": "Hoş Geldin",
"schema": {
"type": "string"
}
},
"400": {
"description": "Hata",
"schema": {
"type": "string"
}
},
"500": {
"description": "Sunucu Hatası",
"description": "Refresh",
"schema": {
"type": "string"
}
}
}
}
},
"/deneme": {
"get": {
"description": "Zamanı gösteren endpoint",
"tags": [
"User Service"
"/register": {
"post": {
"description": "Register to User Auth Service",
"consumes": [
"application/json"
],
"summary": "Zamanı gösteren endpoint",
"produces": [
"application/json"
],
"summary": "Register",
"responses": {
"200": {
"description": "2022-12-30 12:50:00",
"schema": {
"type": "string"
}
},
"400": {
"description": "Hata",
"schema": {
"type": "string"
}
},
"500": {
"description": "Sunucu Hatası",
"schema": {
"type": "string"
}
},
"default": {
"description": "Bilinmeyen Hata",
"description": "Register",
"schema": {
"type": "string"
}
Expand All @@ -144,12 +61,12 @@ const docTemplate = `{

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0.0",
Version: "0.1.0",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "Hello World API",
Description: "This is a sample server for a hello world API.",
Title: "User Auth Service API",
Description: "This is a sample server for a user auth service.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
}
Expand Down
Loading