Skip to content

Commit

Permalink
Rewrite with a cleaner architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
th0th committed Aug 14, 2024
1 parent 1f61cf4 commit 6fe6da4
Show file tree
Hide file tree
Showing 16 changed files with 98,339 additions and 98,253 deletions.
51 changes: 28 additions & 23 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
name: Publish Docker image

name: Build and publish
on:
create:
tags:
- 'v*'
push:
branches:
- main
tags:
- 'v*'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
build-and-publish:
name: Build and publish
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
- name: Log in to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Extract metadata for docker image
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: th0th/is-email-disposable,ghcr.io/th0th/is-email-disposable
images: |
ghcr.io/${{ github.repository }}
${{ github.repository }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@v2
- name: Build and push docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
21 changes: 21 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
linters:
enable:
- gosimple
- govet
- ineffassign
- staticcheck
- bodyclose
- errorlint
- exportloopref
- gocritic
- goprintffuncname
- gosec
- prealloc
- whitespace
linters-settings:
gocritic:
disabled-checks:
- ifElseChain
gosec:
excludes:
- G601
28 changes: 11 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
FROM golang:alpine AS builder
FROM golang:1.23

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
WORKDIR /usr/src/is-email-disposable

WORKDIR /build

COPY go.mod .
COPY go.sum .
COPY go.mod go.sum ./
RUN go mod download

COPY . .
COPY cmd cmd
COPY pkg pkg

RUN mkdir bin

RUN go build -o main .
WORKDIR /dist
RUN cp /build/main .
RUN CGO_ENABLED=0 go build -a -o bin/rest-api cmd/restapi/*

FROM scratch
FROM alpine:3

COPY --from=builder /dist/main /
COPY domains.json /
COPY --from=0 /usr/src/is-email-disposable/bin/rest-api /usr/local/bin/is-email-disposable-rest-api

ENTRYPOINT ["/main"]
ENTRYPOINT ["is-email-disposable-rest-api"]
37 changes: 37 additions & 0 deletions cmd/restapi/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"github.com/go-errors/errors"
"github.com/gofiber/contrib/fiberzerolog"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/rs/zerolog/log"
"github.com/th0th/is-email-disposable/pkg/common"
"github.com/th0th/is-email-disposable/pkg/restapi/handler"
"github.com/th0th/is-email-disposable/pkg/service/domain"
)

func main() {
common.LogSetDefaults()

domainService, err := domain.New()
if err != nil {
log.Panic().Stack().Err(errors.Wrap(err, 0)).Msg("email initialization failed")
}

app := fiber.New(fiber.Config{
DisableStartupMessage: true,
})

app.Use(recover.New(recover.Config{EnableStackTrace: true, StackTraceHandler: func(c *fiber.Ctx, e interface{}) {
log.Error().Stack().Err(errors.Wrap(e.(error), 0)).Msg("fiber panic")
}}))
app.Use(fiberzerolog.New())

app.Get("/", handler.Index(domainService))

err = app.Listen("0.0.0.0:81")
if err != nil {
log.Panic().Stack().Err(errors.Wrap(err, 0)).Msg("fiber listen failed")
}
}
43 changes: 0 additions & 43 deletions domain/domain.go

This file was deleted.

Loading

0 comments on commit 6fe6da4

Please sign in to comment.