Skip to content

Commit

Permalink
Merge pull request #4 from Yinebeb-01/gmain
Browse files Browse the repository at this point in the history
Gmain
  • Loading branch information
yinebebt authored Feb 29, 2024
2 parents ee90eb7 + e15b513 commit 80de1c2
Show file tree
Hide file tree
Showing 28 changed files with 753 additions and 400 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/app
20 changes: 15 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
stages:
- test

image: golang:1.19

.go-cache:
variables:
GOPATH: $CI_PROJECT_DIR/.go
before_script:
- mkdir -p .go
cache:
paths:
- .go/pkg/mod/

test:
extends: .go-cache
stage: test
image: golang:latest
tags:
- gitlab-runner
script:
- go test .
- go test ./...
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
swag:
swag init -g cmd/main.go

test:
go test -v -cover ./test/...

run:
go run ./cmd/main.go

build:
rm app
go build -o app ./cmd/main.go

.PHONY: swag test run build
84 changes: 65 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,76 @@
# ethiopianDateConverter
<p align="center">
<img src="internal/assets/logo_medium.png" alt="logo" width="110" height="110">
</p>
<h1 align="center"><a href="https://pkg.go.dev/gitlab.com/Yinebeb-01/ethiopiandateconverter">Ethiopian Date Converter</a></h1>

## Description
This mini-project s used mainly to convert Ethiopian date(yy-mm-dd) into Gregorian and vise versa.
Ethiopia has its own calander, having 13 months and always have 30 days within a month.
Anybody can use this api; it has easy to use, simply by sending the date along the predefined endpoints,one can get the date as a JSON response.
* [wikipedia](https://en.wikipedia.org/wiki/Ethiopian_calendar)
The Ethiopian Date Converter API is designed to facilitate the conversion between Ethiopian dates
(in the format yy-mm-dd) and Gregorian dates. Ethiopia follows its own calendar system, which consists of 13 months,
each with 30 days.

### contents
If you are newbie to golang, this project will guide and help you on testing(BDD-with Godog), using gin weebframwork and more.
### Functionality
This API allows users to:
* Convert Ethiopian dates to Gregorian dates.
* Convert Gregorian dates to Ethiopian dates.

## Installation
### Usage
To utilize the API, simply send a date using the specified endpoints. The API will respond with the converted date
in JSON format.

#### Example Usage

1. Convert Gregorian Date to Ethiopian Date

```curl
GET /ad-to-et/{date}
```

* Parameters:

`date:` The Gregorian date to convert (in _yy-mm-dd_ format).

1. install using below go command:
- ```go get gitlab.com/Yinebeb-01/ethiopiandateconverter```
**Example**:

2. import onto your project code
- ```import "gitlab.com/Yinebeb-01/ethiopiandateconverter"```
```curl
GET /ad-to-et/2013-09-11
```

## Authors and acknowledgment
- [Yinebeb T.](https://gitlab.com/Yinebeb-01/)
Response:

- You can check the [python version](https://github.com/dimagi/ethiopian-date-converter)
```json
{
"gregorian_date": "2021-05-22"
}
```

## Documentation
Read on [pkg.go.dev](https://pkg.go.dev/gitlab.com/Yinebeb-01/ethiopiandateconverter)
2. Convert Gregorian Date to Ethiopian Date

```curl
GET /et-to-ad/{date}
```

* Parameters:

`date:` The Ethiopia date to convert (in _yy-mm-dd_ format).

**Example**:
```curl
GET /et-to-ad/2021-05-22
```
Response:
```json
{
"ethiopian_date": "2013-09-11"
}
```

## Installation

## Project status
First version, I will come soon with updates
Install using below go command:
```bash
go get gitlab.com/Yinebeb-01/ethiopiandateconverter
```

## Author
- [Yinebeb T.](https://github.com/Yinebeb-01/)
- [python version](https://github.com/dimagi/ethiopian-date-converter)
56 changes: 0 additions & 56 deletions api/getAdFromEt.go

This file was deleted.

49 changes: 0 additions & 49 deletions api/getEtFromAd.go

This file was deleted.

23 changes: 0 additions & 23 deletions api/home.go

This file was deleted.

48 changes: 48 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Ethiopian Calendar tool for Golang
Copyright (c) 2022 Yinebeb Tariku <[email protected]>
*/
package main

import (
"github.com/Yinebeb-01/ethiopiandateconverter/config"
"github.com/Yinebeb-01/ethiopiandateconverter/docs"
"github.com/Yinebeb-01/ethiopiandateconverter/internal/api"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)

// @title EthioGrego
// @version 1.0
// @description Ethiopian to Gregorian date converter server.
// @termsOfService https://st-son.com/terms/
// @contact.name API Support
// @contact.url https://st-son.com/support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url https://www.apache.org/licenses/LICENSE-2.0.html
// @host calendar.st-son.com
// @BasePath /v1
// @securityDefinitions.basic BasicAuth
func main() {
config.InitConfig("config/config.yaml")
docs.SwaggerInfo.Schemes = viper.GetStringSlice("server.schemes")
docs.SwaggerInfo.Host = viper.GetString("server.host")

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)
{
v1.GET("", api.HomePage)
v1.GET("/et-to-ad/:date", api.Gregorian)
v1.GET("/ad-to-et/:date", api.Ethiopian)

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

router.Run(":8080")
}
23 changes: 23 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package config

import (
"context"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"go.uber.org/zap"
"log"
)

func InitConfig(path string) {
viper.SetConfigFile(path)
err := viper.ReadInConfig()
if err != nil {
log.Panic(context.Background(), fmt.Sprintf("Failed to read config: %v", err))
}

viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
log.Panic(context.Background(), "Config file changed:", zap.String("file", e.Name))
})
}
5 changes: 5 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server:
host: localhost:8080
schemes:
- http
- https
Loading

0 comments on commit 80de1c2

Please sign in to comment.