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

fix:update config to support env values #8

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
18 changes: 0 additions & 18 deletions .gitlab-ci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ RUN go mod download

COPY . .

RUN go build -o myapp
RUN go build -o ethiocal

EXPOSE 8080

CMD ["./myapp"]
CMD ["./ethiocal"]
57 changes: 32 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ This API allows users to:
To utilize the API, simply send a date or year using the specified endpoints. For the date conversion,the API will
respond with the converted date in JSON format whereas for the calendar, it will respond data in a json object.

#### Example Usage
#### Documentation

1. Convert Gregorian Date to Ethiopian Date
* <p><a href="https://ethiocal.koyeb.app/v1" target="_blank" >Overview</a></p>

* <p><a href="https://ethiocal.koyeb.app/v1/swagger/index.html" target="_blank" >Try on swagger</a></p>

* <p><a href="https://pkg.go.dev/gihub.com/ethiopiancalendar" target="_blank" >pkg.go.dev</a></p>


v1 Convert Gregorian DOverview Ethiopian Date

```curl
GET /ad-to-et/{date}
Expand Down Expand Up @@ -102,49 +109,49 @@ Response:
"beale_metiq":2,
"mebaja_hamer":18,
"nenewie":{
"DateOfTheMonth":18,
"MonthOfTheYear":6
"date_of_the_month":18,
"month_of_the_year":6
}
},
"fasting":{
"abiy":{
"DateOfTheMonth":2,
"MonthOfTheYear":7
"date_of_the_month":2,
"month_of_the_year":7
},
"debrezeit":{
"DateOfTheMonth":29,
"MonthOfTheYear":7
"date_of_the_month":29,
"month_of_the_year":7
},
"hosanna":{
"DateOfTheMonth":20,
"MonthOfTheYear":8
"date_of_the_month":20,
"month_of_the_year":8
},
"siklet":{
"DateOfTheMonth":25,
"MonthOfTheYear":8
"date_of_the_month":25,
"month_of_the_year":8
},
"tinsaye":{
"DateOfTheMonth":27,
"MonthOfTheYear":8
"date_of_the_month":27,
"month_of_the_year":8
},
"rkbekahnat":{
"DateOfTheMonth":21,
"MonthOfTheYear":9
"date_of_the_month":21,
"month_of_the_year":9
},
"dihnet":{
"DateOfTheMonth":19,
"date_of_the_month":19,
"MonthOfTheYear":10
},
"hawariyat":{
"DateOfTheMonth":17,
"MonthOfTheYear":10
"date_of_the_month":17,
"month_of_the_year":10
},
"erget":{
"DateOfTheMonth":6,
"MonthOfTheYear":10},
"date_of_the_month":6,
"month_of_the_year":10},
"peraklitos":{
"DateOfTheMonth":16,
"MonthOfTheYear":10
"date_of_the_month":16,
"month_of_the_year":10
}
}
}
Expand All @@ -154,8 +161,8 @@ Response:
## Installation
Install using below go command:
```bash
go get gitlab.com/Yinebeb-01/ethiopiandateconverter
go get gitlab.com/yinebebt/thiopiancalendar
```

## Author
- [Yinebeb T.](https://github.com/Yinebeb-01/)
- [Yinebeb T.](https://github.com/yinebebt)
16 changes: 9 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Copyright (c) 2022 Yinebeb Tariku <yintar5@gmail.com>
package main

import (
"fmt"

"github.com/gin-gonic/gin"
"github.com/spf13/viper"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"gitlab.com/Yinebeb-01/ethiopiancalendar/config"
docs "gitlab.com/Yinebeb-01/ethiopiancalendar/docs"
api2 "gitlab.com/Yinebeb-01/ethiopiancalendar/internal/api"
"gitlab.com/yinebebt/ethiopiancalendar/config"
docs "gitlab.com/yinebebt/ethiopiancalendar/docs"
api2 "gitlab.com/yinebebt/ethiopiancalendar/internal/api"
)

// @title EthioGrego
Expand All @@ -28,11 +30,11 @@ import (
// @securityDefinitions.basic BasicAuth
func main() {
config.InitConfig("config/config.yaml")

docs.SwaggerInfo.Schemes = viper.GetStringSlice("server.schemes")
docs.SwaggerInfo.Host = viper.GetString("server.host")
docs.SwaggerInfo.Host = fmt.Sprintf("%v:%v", viper.GetString("server.host"), viper.GetString("server.port"))

router := gin.Default()
docs.SwaggerInfo.BasePath = "/v1"
router.Static("/assets", "./internal/assets")
router.StaticFile("favicon.ico", "internal/assets/favicon.ico")
v1 := router.Group(docs.SwaggerInfo.BasePath)
Expand All @@ -42,8 +44,8 @@ func main() {
v1.GET("/ad-to-et/:date", api2.Ethiopian)
v1.GET("/bahire-hasab/:year", api2.BahireHasab)

router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
v1.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}

router.Run(":8080")
router.Run(fmt.Sprintf("%v:%v", viper.GetString("server.host"), viper.GetString("server.port")))
}
17 changes: 15 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package config
import (
"context"
"fmt"
"log"

"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"go.uber.org/zap"
"log"
)

func InitConfig(path string) {
Expand All @@ -18,6 +19,18 @@ func InitConfig(path string) {

viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
log.Panic(context.Background(), "Config file changed:", zap.String("file", e.Name))
log.Println(context.Background(), "Config file changed:", zap.String("file", e.Name))
})

viper.AutomaticEnv()

bindEnv("server.host", "SERVER_HOST")
bindEnv("server.port", "SERVER_PORT")
bindEnv("server.schemes", "SERVER_SCHEMES")
}

func bindEnv(key, envVar string) {
if err := viper.BindEnv(key, envVar); err != nil {
log.Panic(context.Background(), fmt.Sprintf("failed to bind env variable %s to key %s: %v", envVar, key, err))
}
}
3 changes: 2 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server:
host: localhost:8080
host:
port: 8080
schemes:
- http
- https
11 changes: 7 additions & 4 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"description": "date",
"example": "\"2024-08-12\"",
"description": "Date in yy-mm-dd format",
"name": "date",
"in": "path",
"required": true
Expand Down Expand Up @@ -117,6 +118,7 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"example": "\"2016\"",
"description": "year",
"name": "year",
"in": "path",
Expand Down Expand Up @@ -161,7 +163,8 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"description": "date",
"example": "\"2016-12-06\"",
"description": "Date in yy-mm-dd format",
"name": "date",
"in": "path",
"required": true
Expand Down Expand Up @@ -231,10 +234,10 @@ const docTemplate = `{
"bahirehasab.Date": {
"type": "object",
"properties": {
"dateOfTheMonth": {
"date_of_the_month": {
"type": "integer"
},
"monthOfTheYear": {
"month_of_the_year": {
"type": "integer"
}
}
Expand Down
11 changes: 7 additions & 4 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"parameters": [
{
"type": "string",
"description": "date",
"example": "\"2024-08-12\"",
"description": "Date in yy-mm-dd format",
"name": "date",
"in": "path",
"required": true
Expand Down Expand Up @@ -111,6 +112,7 @@
"parameters": [
{
"type": "string",
"example": "\"2016\"",
"description": "year",
"name": "year",
"in": "path",
Expand Down Expand Up @@ -155,7 +157,8 @@
"parameters": [
{
"type": "string",
"description": "date",
"example": "\"2016-12-06\"",
"description": "Date in yy-mm-dd format",
"name": "date",
"in": "path",
"required": true
Expand Down Expand Up @@ -225,10 +228,10 @@
"bahirehasab.Date": {
"type": "object",
"properties": {
"dateOfTheMonth": {
"date_of_the_month": {
"type": "integer"
},
"monthOfTheYear": {
"month_of_the_year": {
"type": "integer"
}
}
Expand Down
11 changes: 7 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ definitions:
type: object
bahirehasab.Date:
properties:
dateOfTheMonth:
date_of_the_month:
type: integer
monthOfTheYear:
month_of_the_year:
type: integer
type: object
bahirehasab.Fasting:
Expand Down Expand Up @@ -142,7 +142,8 @@ paths:
- application/json
description: Get ethiopian date string from gregorian date
parameters:
- description: date
- description: Date in yy-mm-dd format
example: '"2024-08-12"'
in: path
name: date
required: true
Expand Down Expand Up @@ -173,6 +174,7 @@ paths:
description: Get years fasting and festival date
parameters:
- description: year
example: '"2016"'
in: path
name: year
required: true
Expand Down Expand Up @@ -202,7 +204,8 @@ paths:
- application/json
description: Get gregorian date string from ethiopian date
parameters:
- description: date
- description: Date in yy-mm-dd format
example: '"2016-12-06"'
in: path
name: date
required: true
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module gitlab.com/Yinebeb-01/ethiopiancalendar
module gitlab.com/yinebebt/ethiopiancalendar

go 1.19

Expand Down
7 changes: 4 additions & 3 deletions internal/api/bahirehasab.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package api

import (
"github.com/gin-gonic/gin"
"gitlab.com/Yinebeb-01/ethiopiancalendar/internal/module/bahirehasab"
"net/http"
"strconv"

"github.com/gin-gonic/gin"
"gitlab.com/yinebebt/ethiopiancalendar/internal/module/bahirehasab"
)

// BahireHasab
Expand All @@ -13,7 +14,7 @@ import (
// @Tags Bahirehasab
// @Accept json
// @Produce json
// @Param year path string true "year"
// @Param year path string true "year" example("2016")
// @Success 200 {object} bahirehasab.Festival
// @Failure 400 {object} error
// @Failure 404 {object} error
Expand Down
6 changes: 3 additions & 3 deletions internal/api/date_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/gin-gonic/gin"
"gitlab.com/Yinebeb-01/ethiopiancalendar/internal/module/ethioGrego"
"gitlab.com/yinebebt/ethiopiancalendar/internal/module/ethioGrego"
)

// Ethiopian : Gregorian to Ethiopian date converter
Expand All @@ -17,7 +17,7 @@ import (
// @Tags Date-Conversion
// @Accept json
// @Produce json
// @Param date path string true "date"
// @Param date path string true "Date in yy-mm-dd format" example("2024-08-12")
// @Success 200 {object} time.Time
// @Failure 400 {object} error
// @Failure 404 {object} error
Expand Down Expand Up @@ -60,7 +60,7 @@ func Ethiopian(ctx *gin.Context) {
// @Tags Date-Conversion
// @Accept json
// @Produce json
// @Param date path string true "date"
// @Param date path string true "Date in yy-mm-dd format" example("2016-12-06")
// @Success 200 {object} time.Time
// @Failure 400 {object} error
// @Failure 404 {object} error
Expand Down
Loading
Loading