Skip to content

Commit

Permalink
refactor(project): updated directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
EverythingSuckz committed Nov 28, 2023
1 parent 7c853c0 commit db6d557
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 75 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/generate_changelogs.sh

This file was deleted.

52 changes: 29 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
name: Release
name: Goreleaser

on:
workflow_dispatch:
push:
tags:
- "*"

permissions:
contents: write

jobs:
Release:
if: "contains(github.event.head_commit.message, 'Bump version')"
runs-on: ubuntu-22.04
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup ENV
run: echo "VERSION=$(echo ${{ github.event.head_commit.message }} | sed -r 's/Bump\s+version\s+?(to\s+?)?`?v?([a-z0-9.\-_]+)`?$/\2/')" >> $GITHUB_ENV
- name: Generate CHANGELOGS
run: |
chmod +x .github/workflows/generate_changelogs.sh
./.github/workflows/generate_changelogs.sh > CHANGELOGS.md
- name: Package Server
run: |
rm -fr .vscode .git*
zip -r ${{ github.WORKSPACE }}/TG-FileStreamBot-v${{ env.VERSION }}-main.zip *
- name: Release
uses: softprops/action-gh-release@v1
with:
name: TG-FileStreamBot-v${{ env.VERSION }} (main)
body_path: CHANGELOGS.md
files: |
${{ github.WORKSPACE }}/TG-FileStreamBot-v${{ env.VERSION }}-main.zip
prerelease: false
tag_name: v${{ env.VERSION }}
fetch-depth: 0
- run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
49 changes: 49 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: 1

project_name: TG-FileStreamBot

before:
hooks:
- go mod tidy
- go generate ./...

builds:
- main: ./cmd/fsb/main.go
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

archives:
- format: tar.gz
name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}"
format_overrides:
- goos: windows
format: zip

signs:
- artifacts: checksum
cms: gpg2
args:
- "--batch"
- "-u"
- "{{ .Env.GPG_FINGERPRINT }}"
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"

checksum:
name_template: "{{ .ProjectName }}_checksums.txt"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go"
"program": "./cmd/fsb/main.go",
}
]
}
12 changes: 6 additions & 6 deletions main.go → cmd/fsb/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"EverythingSuckz/fsb/bot"
"EverythingSuckz/fsb/cache"
"EverythingSuckz/fsb/config"
"EverythingSuckz/fsb/routes"
"EverythingSuckz/fsb/types"
"EverythingSuckz/fsb/utils"
"EverythingSuckz/fsb/internal/bot"
"EverythingSuckz/fsb/internal/cache"
"EverythingSuckz/fsb/internal/routes"
"EverythingSuckz/fsb/internal/types"
"EverythingSuckz/fsb/internal/utils"
"fmt"
"net/http"
"time"
Expand All @@ -15,7 +15,7 @@ import (
"go.uber.org/zap"
)

const versionString = "v0.0.0"
const versionString = "3.0.0-alpha1"

var startTime time.Time = time.Now()

Expand Down
34 changes: 24 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@ package config

import (
"os"
"path"
"path/filepath"
"reflect"
"regexp"
"runtime"
"strconv"
"strings"

_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
"go.uber.org/zap"
)

var ValueOf = &config{}

type config struct {
ApiID int32 `envconfig:"API_ID" required:"true"`
ApiHash string `envconfig:"API_HASH" required:"true"`
BotToken string `envconfig:"BOT_TOKEN" required:"true"`
LogChannelID int64 `envconfig:"LOG_CHANNEL" required:"true"`
Dev bool `envconfig:"DEV" default:"false"`
Port int `envconfig:"PORT" default:"8080"`
Host string `envconfig:"HOST" default:"http://localhost:8080"`
HashLength int `envconfig:"HASH_LENGTH" default:"6"`
ApiID int32 `envconfig:"API_ID" required:"true"`
ApiHash string `envconfig:"API_HASH" required:"true"`
BotToken string `envconfig:"BOT_TOKEN" required:"true"`
LogChannelID int64 `envconfig:"LOG_CHANNEL" required:"true"`
Dev bool `envconfig:"DEV" default:"false"`
Port int `envconfig:"PORT" default:"8080"`
Host string `envconfig:"HOST" default:"http://localhost:8080"`
HashLength int `envconfig:"HASH_LENGTH" default:"6"`
UseSessionFile bool `envconfig:"USE_SESSION_FILE" default:"true"`
MultiTokens []string
}

var botTokenRegex = regexp.MustCompile(`MULTI\_TOKEN[\d+]=(.*)`)

func (c *config) setupEnvVars() {
err := envconfig.Process("", c)
envPath := filepath.Join(callerDir(), "fsb.env")
err := godotenv.Load(envPath)
if err != nil {
panic(err)
}
err = envconfig.Process("", c)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -79,3 +87,9 @@ func abs(x int) int {
}
return x
}

func callerDir() string {
_, b, _, _ := runtime.Caller(0)
d := path.Join(path.Dir(b))
return filepath.Dir(d)
}
2 changes: 1 addition & 1 deletion bot/client.go → internal/bot/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bot

import (
"EverythingSuckz/fsb/commands"
"EverythingSuckz/fsb/internal/commands"
"EverythingSuckz/fsb/config"

"go.uber.org/zap"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cache/cache.go → internal/cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cache

import (
"EverythingSuckz/fsb/types"
"EverythingSuckz/fsb/internal/types"
"bytes"
"encoding/gob"
"sync"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion commands/stream.go → internal/commands/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"EverythingSuckz/fsb/config"
"EverythingSuckz/fsb/utils"
"EverythingSuckz/fsb/internal/utils"

"github.com/celestix/gotgproto/dispatcher"
"github.com/celestix/gotgproto/dispatcher/handlers"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions routes/stream.go → internal/routes/stream.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package routes

import (
"EverythingSuckz/fsb/bot"
"EverythingSuckz/fsb/utils"
"EverythingSuckz/fsb/internal/bot"
"EverythingSuckz/fsb/internal/utils"
"fmt"
"io"
"net/http"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/hashing.go → internal/utils/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"EverythingSuckz/fsb/config"
"EverythingSuckz/fsb/types"
"EverythingSuckz/fsb/internal/types"
)

func PackFile(fileName string, fileSize int64, mimeType string, fileID int64) string {
Expand Down
4 changes: 2 additions & 2 deletions utils/helpers.go → internal/utils/helpers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package utils

import (
"EverythingSuckz/fsb/cache"
"EverythingSuckz/fsb/config"
"EverythingSuckz/fsb/types"
"EverythingSuckz/fsb/internal/cache"
"EverythingSuckz/fsb/internal/types"
"context"
"errors"
"fmt"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit db6d557

Please sign in to comment.