-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change config management from env to yaml (#9)
* disable test caching * switch config from env to yaml * update readme to match the new changes about config file * add production ready docker compose file * force recreate of container with docker compose * update CI workflow * update CI workflow * update CI workflow * update CI workflow
- Loading branch information
1 parent
7dbbbfe
commit 62e0c92
Showing
17 changed files
with
155 additions
and
91 deletions.
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
.env.test | ||
*.env | ||
*.env | ||
config.yaml | ||
config | ||
/config.example.yaml | ||
/config.test.example.yaml |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,3 +1,6 @@ | ||
.idea | ||
.env.test | ||
*.env | ||
*.env | ||
config.yaml | ||
config.test.yaml | ||
config |
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
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
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,17 +1,30 @@ | ||
# Telegram Bot Storage(in development) | ||
|
||
![Build Status](https://github.com/dipandaaser/tg-bot-storage/workflows/CI/badge.svg) | ||
[![License](https://img.shields.io/github/license/dipandaaser/tg-bot-storage)](LICENSE) | ||
[![Release](https://img.shields.io/github/release/dipandaaser/tg-bot-storage.svg)](https://github.com/dipandaaser/tg-bot-storage/releases/latest) | ||
[![GitHub Releases Stats of tg-bot-storage](https://img.shields.io/github/downloads/dipandaaser/tg-bot-storage/total.svg?logo=github)](https://somsubhra.github.io/github-release-stats/?username=dipandaaser&repository=tg-bot-storage) | ||
|
||
Telegram Bot Storage is a simple library for storing files in Telegram using bot and by passing limits listed on [telegram bot limits website](https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this) | ||
Telegram Bot Storage is a simple library for storing files in Telegram using bot and by passing limits listed | ||
on [telegram bot limits website](https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this) | ||
|
||
### Development | ||
|
||
#### Dependencies | ||
|
||
- Golang 1.16+ | ||
- GNU Make | ||
|
||
#### How to run | ||
|
||
Create a `config.yaml` file under the [config](config) folder.Use [config.example.yaml](config.example.yaml) as a | ||
template to fill the file. | ||
|
||
Run the following command: `make run` or `go run ./cmd/main.go` | ||
|
||
|
||
#### How to test | ||
Create a `.env.test` file with [.env.test.example](.env.test.example) as a template OR just set env var with the same name. | ||
Run the following command: `make test` | ||
Create a `config.yaml` file under the [config-test](config-test) | ||
folder. Use [config.test.example.yaml](config.example.yaml) as a template to fill the file | ||
|
||
Run the following commands: `make test` and `make docker-e2etest` |
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,36 @@ | ||
// | ||
package config_test | ||
|
||
import ( | ||
"github.com/DipandaAser/tg-bot-storage/internal/config" | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
) | ||
|
||
type Config struct { | ||
config.Config `yaml:",inline"` | ||
//ChatID is the ID of the chat to store message, this is use in some test | ||
ChatID int64 `yaml:"chat_id"` | ||
//DraftChatID is the ID of the chat used as a draft chat when downloading file | ||
DraftChatID int64 `yaml:"draft_chat_id"` | ||
} | ||
|
||
var defaultConfig *Config | ||
|
||
//GetDefaultConfig returns a config with default values from the yaml configFilePath | ||
func GetConfig(configFilePath string) Config { | ||
if defaultConfig == nil { | ||
defaultConfig = &Config{Config: config.Config{Tokens: make([]string, 0)}} | ||
file, err := os.Open(configFilePath) | ||
if err != nil { | ||
return Config{} | ||
} | ||
defer file.Close() | ||
|
||
err = yaml.NewDecoder(file).Decode(defaultConfig) | ||
if err != nil { | ||
return Config{} | ||
} | ||
} | ||
return *defaultConfig | ||
} |
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,5 @@ | ||
tokens: | ||
- "bot token 1" | ||
- "bot token 2" | ||
- "bot token 3" | ||
api_key: "" |
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,9 @@ | ||
tokens: | ||
- "bot token 1" | ||
- "bot token 2" | ||
- "bot token 3" | ||
api_key: "" | ||
#chat_id(int) is the ID of the chat to store message, this is use in some test | ||
chat_id: | ||
#draft_chat_id(int) is the ID of the chat used as a draft chat when downloading file | ||
draft_chat_id: |
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
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 @@ | ||
version: '3' | ||
|
||
services: | ||
bot-storage: | ||
image: ghcr.io/dipandaaser/bot-storage:latest | ||
restart: on-failure | ||
ports: | ||
- "7000:7000" | ||
volumes: | ||
- "./config:/app/config" |
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
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
Oops, something went wrong.