-
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 2077255
Showing
51 changed files
with
2,438 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format | ||
|
||
# Working directory | ||
# . or absolute path, please note that the directories following must be under root | ||
root = "." | ||
tmp_dir = "LDE/tmp" | ||
|
||
[build] | ||
# Just plain old shell command. You could use `make` as well. | ||
cmd = "go build -o ./LDE/tmp/main ./cmd/app/main.go" | ||
# Binary file yields from `cmd`. | ||
bin = "LDE/tmp/main" | ||
|
||
# Customize binary. | ||
# This is how you start to run your application. Since my application will works like CLI, so to run it, like to make a CLI call. | ||
# full_bin = "./services/notifier/tmp/build/engine http" | ||
# This log file places in your tmp_dir. | ||
log = "air_errors.log" | ||
# Watch these filename extensions. | ||
|
||
include_dir = [] | ||
include_ext = ["go", "tpl", "yaml", "yml", "env"] | ||
# Ignore these filename extensions or directories. | ||
exclude_dir = ["tmp", "tmp_schema", "deploy", "docker", "assets", "tests", "dist", "LDE", "vendor.protogen", "infra"] | ||
# It's not necessary to trigger build each time file changes if it's too frequent. | ||
delay = 1000 | ||
kill_delay = 10 | ||
|
||
[log] | ||
# Show log time | ||
main_only = false | ||
time = true | ||
[color] | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[misc] | ||
# Delete tmp directory on exit | ||
clean_on_exit = true | ||
|
||
[screen] | ||
clear_on_rebuild = true | ||
keep_scroll = true |
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,67 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.21.6" | ||
cache-dependency-path: go.sum | ||
|
||
- name: Build | ||
run: go build -o ./bin/ -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... | ||
|
||
linter: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.21.6" | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
# Require: The version of golangci-lint to use. | ||
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. | ||
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. | ||
version: v1.53 | ||
|
||
# Optional: working directory, useful for monorepos | ||
# working-directory: somedir | ||
|
||
# Optional: golangci-lint command line arguments. | ||
# | ||
# Note: By default, the `.golangci.yml` file should be at the root of the repository. | ||
# The location of the configuration file can be changed by using `--config=` | ||
args: --timeout=30m --config=./.golangci.pipeline.yaml --issues-exit-code=0 | ||
|
||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
# only-new-issues: true | ||
|
||
# Optional: if set to true, then all caching functionality will be completely disabled, | ||
# takes precedence over all other caching options. | ||
# skip-cache: true | ||
|
||
# Optional: if set to true, then the action won't cache or restore ~/go/pkg. | ||
# skip-pkg-cache: true | ||
|
||
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. | ||
# skip-build-cache: true | ||
|
||
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. | ||
# install-mode: "goinstall" |
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,20 @@ | ||
**/.DS_Store | ||
**/.idea | ||
**/.vscode | ||
**/bin | ||
|
||
**/.env* | ||
!.env.example | ||
|
||
**/vendor* | ||
|
||
**/logs | ||
**/*.log | ||
LDE | ||
_go.LDE.mod | ||
_go.LDE.sum | ||
config.yml | ||
*.db | ||
*.png | ||
*.jpg | ||
|
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,54 @@ | ||
# More info on config here: https://golangci-lint.run/usage/configuration/#config-file | ||
run: | ||
concurrency: 8 | ||
timeout: 10m | ||
issues-exit-code: 1 | ||
tests: true | ||
skip-dirs: | ||
- bin | ||
- vendor | ||
- var | ||
- tmp | ||
- .cache | ||
skip-files: | ||
- \.pb\.go$ | ||
- \.pb\.gw\.go$ | ||
|
||
output: | ||
format: colored-line-number | ||
print-issued-lines: true | ||
print-linter-name: true | ||
|
||
linters-settings: | ||
govet: | ||
check-shadowing: true | ||
dupl: | ||
threshold: 100 | ||
goconst: | ||
min-len: 2 | ||
min-occurrences: 2 | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- errcheck | ||
- goconst | ||
- goimports | ||
- gosec | ||
- govet | ||
- ineffassign | ||
- megacheck | ||
- revive | ||
- typecheck | ||
- unused | ||
|
||
issues: | ||
exclude-use-default: false | ||
exclude: | ||
# _ instead of err checks | ||
- should have comment or be unexported | ||
- comment on exported var | ||
- G104 | ||
- exported func .* returns unexported type .*, which can be annoying to use | ||
- should have a package comment | ||
- don't use an underscore in package name |
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) 2024 Nazarii | ||
|
||
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,94 @@ | ||
include .env | ||
|
||
LOCAL_BIN := $(CURDIR)/LDE/bin | ||
|
||
|
||
# Dependencies =============== | ||
|
||
install: | ||
mkdir -p $(LOCAL_BIN) | ||
make install-golangci-lint | ||
make install-go-air-livereload | ||
|
||
install-golangci-lint: | ||
GOBIN=$(LOCAL_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3 | ||
|
||
install-go-air-livereload: | ||
GOBIN=$(LOCAL_BIN) go install github.com/cosmtrek/air@v1.51.0 | ||
|
||
# ============================ | ||
|
||
|
||
|
||
# Go Dependencies ============ | ||
|
||
t: | ||
go mod tidy | ||
|
||
# ============================ | ||
|
||
|
||
|
||
|
||
# Main ======================= | ||
|
||
|
||
run: | ||
# make lint | ||
|
||
go run cmd/app/main.go | ||
|
||
run-watch: | ||
$(LOCAL_BIN)/air -c .air.toml | ||
|
||
lint: | ||
$(LOCAL_BIN)/golangci-lint run ./... --config .golangci.pipeline.yaml | ||
|
||
build: | ||
go build -o bin/app cmd/app/main.go | ||
|
||
build-win: | ||
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build -o bin/app.exe cmd/app/main.go | ||
|
||
local-build: | ||
go build -o bin/macos/autoposter cmd/app/main.go | ||
cp config.yml.example bin/macos/config.yml | ||
cp README.md bin/macos/README.md | ||
|
||
local-build-win: | ||
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build -o bin/win64/autoposter.exe cmd/app/main.go | ||
cp config.yml.example bin/win64/config.yml | ||
cp README.md bin/win64/README.md | ||
|
||
# ============================ | ||
|
||
|
||
|
||
|
||
# Datavase migrations ======== | ||
|
||
local-migration-create: | ||
make _required_param-name | ||
|
||
$(LOCAL_BIN)/goose -dir ${MIGRATIONS_DIR} create $(name) sql | ||
|
||
local-migration-status: | ||
$(LOCAL_BIN)/goose -dir ${MIGRATIONS_DIR} sqlite3 ${SQLITE_FILE} status -v | ||
|
||
local-migration-up: | ||
$(LOCAL_BIN)/goose -dir ${MIGRATIONS_DIR} sqlite3 ${SQLITE_FILE} up -v | ||
|
||
local-migration-down: | ||
$(LOCAL_BIN)/goose -dir ${MIGRATIONS_DIR} sqlite3 ${SQLITE_FILE} down -v | ||
|
||
# ============================ | ||
|
||
|
||
|
||
|
||
# Make sys =================== | ||
|
||
_required_param-%: | ||
@if [ "${${*}}" == "" ]; then echo "\n\033[0;91mPlease provide arg: \"$*\"\033[0m\n"; exit 1; fi | ||
|
||
# ============================ |
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,26 @@ | ||
# go-discord-autoposter | ||
|
||
### Getting access token from Discord | ||
|
||
1. Open discord from your browser and login to your account. (or enable debug mode in discord app) | ||
2. Press `Ctrl + Shift + I` to open developer tools. (or `Option + Command + I` on macOS) | ||
3. Paste the following code in the console and press enter. | ||
|
||
```js | ||
const i = document.createElement("iframe"); | ||
i.onload = () => | ||
console.log( | ||
"%c" + i.contentWindow.localStorage.getItem("token").slice(1, -1), | ||
"color: red;font-size: 24px" | ||
); | ||
i.src = "about:blank"; | ||
document.body.appendChild(i); | ||
``` | ||
|
||
4. You will see a red text in the console. That is your access token. | ||
|
||
### Getting channel id from Discord | ||
|
||
1. Open discord from your browser and login to your account. (or discord app) | ||
2. Enable developer mode in discord settings. | ||
3. Right click on the channel you want to post and click on `Copy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
_ "github.com/mattn/go-sqlite3" | ||
|
||
"github.com/wenzzy/go-discord-autoposter/internal/app" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
a, err := app.NewApp(ctx) | ||
if err != nil { | ||
log.Fatalf("failed to init app: %s", err.Error()) | ||
} | ||
|
||
err = a.Run() | ||
if err != nil { | ||
log.Fatalf("failed to run app: %s", err.Error()) | ||
} | ||
} |
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,18 @@ | ||
app_env: dev # dev - logs will prints in console / prod - logs will prints in logs_path | ||
db_file: ./autoposter.db | ||
logs_level: debug | ||
logs_path: logs/app.log | ||
discord_token: Ga01Rj4fY8qRfun09JvwTyno.45yFKK.j6kwUoL355zdwg4IfTe9C2aelieSlYkKmz51GU | ||
messages: | ||
- topic: News about my life # optional, only for readability in logs | ||
channel_name: MainChannel # optional, only for readability in logs | ||
channel_id: 949589493854354345 | ||
interval: 2m # ex.: 1h20m, 2d1h50m, 30s | ||
text: > | ||
My first | ||
multiline | ||
message | ||
files: | ||
- image.png |
Oops, something went wrong.