Skip to content

Commit

Permalink
chore: refine folder structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
omegaatt36 committed Aug 7, 2024
1 parent 02c654b commit 96ec150
Show file tree
Hide file tree
Showing 27 changed files with 52 additions and 79 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ jobs:

steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2.1.3
uses: actions/setup-go@v5.0.2
with:
go-version: ${{ matrix.go }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2.3.4
uses: actions/checkout@v4.1.7

- name: Cache modules
uses: actions/cache@v2.1.6
uses: actions/cache@v4.0.2
with:
# In order:
# * Module download cache
Expand All @@ -46,14 +46,4 @@ jobs:
${{ runner.os }}-go-
- name: Build
run: go build

# - name: Test
# run: go test -p 1 -coverpkg ./... -covermode atomic -coverprofile coverage.txt ./...

# - name: Upload coverage to Codecov
# uses: codecov/[email protected]
# if: matrix.os == 'ubuntu-latest'
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: ./coverage.txt
run: go build cmd/bot/main.go
27 changes: 3 additions & 24 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --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 the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
- uses: actions/[email protected]
- name: Lint and Test
run: make test
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ENV GOPROXY=https://proxy.golang.org
ENV APP_NAME=insta-fetcher

# Build binary file
RUN ["go", "build", "-o", "build/${APP_NAME}"]
RUN ["go", "build", "-o", "build/${APP_NAME}", "cmd/bot/main.go"]

#
# Development build
Expand Down
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ BUILD_DIR=build

.PHONY: fmt check test

all: fmt check test
all: dependency fmt check test

dependency:
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/daixiang0/gci@latest
go install github.com/client9/misspell/cmd/misspell@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

fmt:
gofmt -s -w -l .
@echo 'goimports' && goimports -w -local gobe $(shell find . -type f -name '*.go' -not -path "./internal/*")
gci write -s standard -s default -s "Prefix(gobe)" --skip-generated .
@echo 'goimports' && goimports -w -local github.com/omegaatt36/instagramrobot $(shell find . -type f -name '*.go')
gci write -s standard -s default -s "Prefix(github.com/omegaatt36/instagramrobot)" --skip-generated .
go mod tidy

check:
go vet -all ./...
golangci-lint run
misspell -error */**
@echo 'staticcheck' && staticcheck $(shell go list ./... | grep -v internal)

vet:
./vet.sh
@echo 'staticcheck' && staticcheck $(shell go list ./...)

test:
go test ./...
go test ./...
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ go run main.go --bot-token=***** --app-env=development
### Installing via Kubernetes by using helm

```shell
pushd charts
pushd deploy/charts/bot
helm upgrade --install -v values.yaml insta-fetcher .
popd
```
Expand All @@ -70,7 +70,7 @@ docker compose build
#### Running the container

```sh
docker compose up
docker compose up -f deploy/docker-compose.yml
```

### Installing as a service
Expand All @@ -82,7 +82,7 @@ Make sure that the project files exist in the `/usr/local/instagramrobot` direct
> If you don't have Go installed, [click here](https://golang.org/doc/install) and follow its instructions.
```sh
go build -o bin/insta-fetcher
go build cmd/bot/main.go -o bin/insta-fetcher
```

#### Register the service
Expand Down
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"runtime/debug"
"syscall"

"github.com/omegaatt36/instagramrobot/cliflag"

"github.com/urfave/cli/v2"

"github.com/omegaatt36/instagramrobot/cliflag"
)

// App is cli wrapper that do some common operation and creates signal handler.
Expand Down
4 changes: 2 additions & 2 deletions app/bot/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"regexp"

"gopkg.in/telebot.v3"

"github.com/omegaatt36/instagramrobot/appmodule/instagram"
"github.com/omegaatt36/instagramrobot/appmodule/providers"
"github.com/omegaatt36/instagramrobot/appmodule/telegram"
"github.com/omegaatt36/instagramrobot/appmodule/threads"
"github.com/omegaatt36/instagramrobot/logging"

"gopkg.in/telebot.v3"
)

// Controller is the main controller for the bot.
Expand Down
3 changes: 2 additions & 1 deletion app/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"time"

"gopkg.in/telebot.v3"

"github.com/omegaatt36/instagramrobot/app/bot/api"
"github.com/omegaatt36/instagramrobot/app/bot/config"
"github.com/omegaatt36/instagramrobot/logging"
"gopkg.in/telebot.v3"
)

var b *telebot.Bot
Expand Down
3 changes: 2 additions & 1 deletion app/bot/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
package config

import (
"github.com/omegaatt36/instagramrobot/cliflag"
"github.com/urfave/cli/v2"

"github.com/omegaatt36/instagramrobot/cliflag"
)

// Env represents the environment of the application.
Expand Down
1 change: 1 addition & 0 deletions appmodule/instagram/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

browser "github.com/EDDYCJY/fake-useragent"
"github.com/gocolly/colly/v2"

"github.com/omegaatt36/instagramrobot/domain"
)

Expand Down
3 changes: 2 additions & 1 deletion appmodule/telegram/media-sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package telegram
import (
"fmt"

"gopkg.in/telebot.v3"

"github.com/omegaatt36/instagramrobot/domain"
"github.com/omegaatt36/instagramrobot/logging"
"gopkg.in/telebot.v3"
)

type MediaSender struct {
Expand Down
1 change: 1 addition & 0 deletions appmodule/threads/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/gocolly/colly/v2"

"github.com/omegaatt36/instagramrobot/domain"
)

Expand Down
3 changes: 2 additions & 1 deletion main.go → cmd/bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"context"

"github.com/urfave/cli/v2"

"github.com/omegaatt36/instagramrobot/app"
"github.com/omegaatt36/instagramrobot/app/bot"
"github.com/omegaatt36/instagramrobot/app/bot/config"
"github.com/omegaatt36/instagramrobot/health"
"github.com/omegaatt36/instagramrobot/logging"
"github.com/urfave/cli/v2"
)

// Main is the entry point of the application.
Expand Down
7 changes: 2 additions & 5 deletions cmd/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"context"

"github.com/urfave/cli/v2"

"github.com/omegaatt36/instagramrobot/app"
"github.com/omegaatt36/instagramrobot/app/web"
"github.com/omegaatt36/instagramrobot/health"
"github.com/omegaatt36/instagramrobot/logging"
"github.com/urfave/cli/v2"
)

// Main is the entry point of the application.
Expand All @@ -16,10 +17,6 @@ func Main(ctx context.Context) {

go health.StartServer()

// if err := bot.Register(config.BotToken()); err != nil {
// logging.Fatalf("couldn't register the Telegram bot: %v", err)
// }

stopped := web.NewServer().Start(ctx)

<-stopped
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.8"

services:
bot:
restart: always
image: omegaatt36/insta-fetcher:latest
environment:
- APP_ENV=production
- BOT_TOKEN=FILL_ME
12 changes: 0 additions & 12 deletions docker-compose.yml

This file was deleted.

3 changes: 2 additions & 1 deletion health/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"sync"
"time"

"github.com/omegaatt36/instagramrobot/logging"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/omegaatt36/instagramrobot/logging"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions logging/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
package logging

import (
"github.com/omegaatt36/instagramrobot/cliflag"

"github.com/urfave/cli/v2"
"go.uber.org/zap"

"github.com/omegaatt36/instagramrobot/cliflag"
)

type cfg struct {
Expand Down

0 comments on commit 96ec150

Please sign in to comment.