-
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.
- Loading branch information
0 parents
commit 3ccdb86
Showing
25 changed files
with
1,339 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,126 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/goland | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=goland | ||
|
||
### GoLand ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# AWS User-specific | ||
.idea/**/aws.xml | ||
|
||
# Generated files | ||
.idea/**/contentModel.xml | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Gradle and Maven with auto-import | ||
# When using Gradle or Maven with auto-import, you should exclude module files, | ||
# since they will be recreated, and may cause churn. Uncomment if using | ||
# auto-import. | ||
# .idea/artifacts | ||
# .idea/compiler.xml | ||
# .idea/jarRepositories.xml | ||
# .idea/modules.xml | ||
# .idea/*.iml | ||
# .idea/modules | ||
# *.iml | ||
# *.ipr | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# SonarLint plugin | ||
.idea/sonarlint/ | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
### GoLand Patch ### | ||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 | ||
|
||
# *.iml | ||
# modules.xml | ||
# .idea/misc.xml | ||
# *.ipr | ||
|
||
# Sonarlint plugin | ||
# https://plugins.jetbrains.com/plugin/7973-sonarlint | ||
.idea/**/sonarlint/ | ||
|
||
# SonarQube Plugin | ||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin | ||
.idea/**/sonarIssues.xml | ||
|
||
# Markdown Navigator plugin | ||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced | ||
.idea/**/markdown-navigator.xml | ||
.idea/**/markdown-navigator-enh.xml | ||
.idea/**/markdown-navigator/ | ||
|
||
# Cache file creation bug | ||
# See https://youtrack.jetbrains.com/issue/JBR-2257 | ||
.idea/$CACHE_FILE$ | ||
|
||
# CodeStream plugin | ||
# https://plugins.jetbrains.com/plugin/12206-codestream | ||
.idea/codestream.xml | ||
|
||
# Azure Toolkit for IntelliJ plugin | ||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij | ||
.idea/**/azureSettings.xml | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/goland | ||
|
||
# Envs | ||
.env | ||
|
||
# VScode | ||
.vscode/ | ||
|
||
# Badger | ||
data/ |
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,51 @@ | ||
repos: | ||
- repo: https://github.com/tekwizely/pre-commit-golang | ||
rev: v1.0.0-rc.1 | ||
hooks: | ||
# | ||
# Go Build | ||
# | ||
- id: go-build-mod | ||
- id: go-build-repo-mod | ||
# | ||
# Go Mod Tidy | ||
# | ||
- id: go-mod-tidy | ||
- id: go-mod-tidy-repo | ||
# | ||
# Go Test | ||
# | ||
- id: go-test-mod | ||
- id: go-test-repo-mod | ||
# | ||
# Go Vet | ||
# | ||
# TEMPORARILY DISABLED | ||
# - id: go-vet | ||
- id: go-vet-mod | ||
- id: go-vet-repo-mod | ||
# | ||
# Revive | ||
# | ||
- id: go-revive | ||
- id: go-revive-mod | ||
- id: go-revive-repo-mod | ||
# | ||
# GoSec | ||
# | ||
- id: go-sec-mod | ||
- id: go-sec-repo-mod | ||
# | ||
# StaticCheck | ||
# | ||
- id: go-staticcheck-mod | ||
- id: go-staticcheck-repo-mod | ||
# | ||
# Formatters | ||
# | ||
- id: go-fmt | ||
- id: go-fmt-repo | ||
# | ||
# Style Checkers | ||
# | ||
- id: go-critic |
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 @@ | ||
FROM golang:1.19 as build | ||
|
||
WORKDIR /go/src/app | ||
COPY . . | ||
|
||
RUN go mod download | ||
RUN go vet -v | ||
# RUN go test -v | ||
|
||
RUN CGO_ENABLED=0 go build -o /go/bin/app | ||
|
||
FROM gcr.io/distroless/static-debian11 | ||
|
||
COPY --from=build /go/bin/app / | ||
CMD ["/app"] |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 lefes | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# Discord Message Scheduler |
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,4 @@ | ||
# TODO file for the project | ||
|
||
- [ ] Add a README.md file to the project | ||
- [ ] Fix go vet issues |
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,110 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/lefes/discord-message-scheduler/internal/config" | ||
"github.com/lefes/discord-message-scheduler/internal/transport/discord" | ||
"github.com/lefes/discord-message-scheduler/internal/transport/http" | ||
"github.com/lefes/discord-message-scheduler/pkg/database/badgerdb" | ||
"github.com/lefes/discord-message-scheduler/pkg/logger" | ||
) | ||
|
||
func main() { | ||
// Config init | ||
cfg, err := config.Init() | ||
if err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
|
||
// BadgerDB init | ||
db, err := badgerdb.NewClient(cfg.DB) | ||
if err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
|
||
defer db.Close() | ||
|
||
// // Repositories and services | ||
// repos := repository.NewRepositories(db) | ||
// services := service.NewServices(service.Deps{ | ||
// Repos: repos, | ||
// }) | ||
|
||
// HTTP server | ||
// TODO: rework handlers registration | ||
httpServer := http.NewServer(cfg, nil) | ||
httpServer.RegisterHandlers() | ||
|
||
go func() { | ||
if err := httpServer.Start(); err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
}() | ||
|
||
logger.Info("Server is running...") | ||
|
||
// Discord client | ||
discordClient, err := discord.NewClient(&cfg.Discord) | ||
if err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
|
||
if err := discordClient.Start(); err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
|
||
logger.Info("Discord client is running...") | ||
|
||
// Graceful shutdown | ||
quit := make(chan os.Signal, 1) | ||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
<-quit | ||
|
||
logger.Info("Shutting down...") | ||
|
||
if err := discordClient.Shutdown(); err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
logger.Info("Discord client gracefully stopped") | ||
|
||
const timeout = 5 * time.Second | ||
|
||
ctx, shutdown := context.WithTimeout(context.Background(), timeout) | ||
defer shutdown() | ||
|
||
if err := httpServer.Shutdown(ctx); err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
logger.Info("Server gracefully stopped") | ||
|
||
// Close DB | ||
err = db.Close() | ||
if err != nil { | ||
logger.Error(err) | ||
|
||
return | ||
} | ||
|
||
logger.Info("DB gracefully stopped") | ||
|
||
} |
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 @@ | ||
module github.com/lefes/discord-message-scheduler | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/bwmarrin/discordgo v0.27.1 | ||
github.com/dgraph-io/badger/v4 v4.0.1 | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/sirupsen/logrus v1.9.0 | ||
github.com/spf13/viper v1.15.0 | ||
) | ||
|
||
require ( | ||
github.com/cespare/xxhash v1.1.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/dgraph-io/ristretto v0.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.0 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/flatbuffers v2.0.0+incompatible // indirect | ||
github.com/gorilla/websocket v1.4.2 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/klauspost/compress v1.13.1 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.6 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/spf13/afero v1.9.3 // indirect | ||
github.com/spf13/cast v1.5.0 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.4.2 // indirect | ||
go.opencensus.io v0.24.0 // indirect | ||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect | ||
golang.org/x/net v0.4.0 // indirect | ||
golang.org/x/sys v0.3.0 // indirect | ||
golang.org/x/text v0.5.0 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.