Skip to content

Commit

Permalink
Merge pull request #193 from foomo/service-goroutine
Browse files Browse the repository at this point in the history
Add goroutine service
  • Loading branch information
franklinkim authored Oct 18, 2023
2 parents 6e0d907 + ffd01bf commit bbd9088
Show file tree
Hide file tree
Showing 83 changed files with 1,641 additions and 457 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ on:
- v*.*.*
workflow_dispatch:

env:
GOFLAGS: -mod=readonly
GOPROXY: https://proxy.golang.org
permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- run: git fetch --force --tags

- uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: 'go.mod'
go-version: 'stable'

- uses: goreleaser/goreleaser-action@v4
with:
Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
merge_group:
branches: [ main ]
workflow_dispatch:

env:
GOFLAGS: -mod=readonly
GOPROXY: https://proxy.golang.org

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
Expand All @@ -21,15 +14,24 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
check-latest: true
go-version-file: 'go.mod'
go-version: 'stable'

- uses: gotesttools/gotestfmt-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m

- name: Run tests
run: go test -v ./...
- run: make test

- uses: coverallsapp/github-action@v2
with:
file: coverage.out

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
.*
*.log
*.out
!.github/
!.husky/
!.editorconfig
!.gitignore
!.golangci.yml
!.goreleaser.yml
!.husky.yaml
/coverage.out
/coverage.html
/tmp/
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
run:
timeout: 5m
skip-dirs:
- tmp

linters-settings:
# https://golangci-lint.run/usage/linters/#revive
Expand Down Expand Up @@ -61,7 +62,7 @@ linters:
- gosec # (gas): Inspects source code for security problems [fast: false, auto-fix: false]
- grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
#- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
Expand Down
31 changes: 1 addition & 30 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,4 @@ builds:
- skip: true

changelog:
filters:
exclude:
- "^wip"
- "^test"
- "^docs"
- "^chore"
- "^style"
- "go mod tidy"
- "merge conflict"
- "Merge pull request"
- "Merge remote-tracking branch"
- "Merge branch"
groups:
- title: Features
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 0
- title: Dependency updates
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
order: 100
- title: "Bug fixes"
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 150
- title: "Security"
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
order: 200
- title: "Performace"
regexp: '^.*?perf(\([[:word:]]+\))??!?:.+$'
order: 250
- title: Other
order: 999
use: github-native
2 changes: 0 additions & 2 deletions .husky.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ hooks:
lint-staged:
'*.go':
- goimports -l -w
- gofmt -l -w

lint-commit:
email: '^([email protected])$'
types: '^(feat|fix|build|chore|docs|perf|refactor|revert|style|test|wip)$'
header: '^(?P<type>\w+)(\((?P<scope>[\w/.-]+)\))?(?P<breaking>!)?:( +)?(?P<header>.+)'
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ doc:
.PHONY: test
## Run tests
test:
@go test -v ./...

.PHONY: test.cover
## Run tests with coverage
test.cover:
@go test -v -coverprofile=coverage.out ./...
@go tool cover -func=coverage.out
@go tool cover -html=coverage.out
@go test -coverprofile=coverage.out -race -json ./... | gotestfmt

.PHONY: lint
## Run linter
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# keel

[![Build Status](https://github.com/foomo/keel/actions/workflows/test.yml/badge.svg?branch=main&event=push)](https://github.com/foomo/keel/actions/workflows/test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/foomo/keel)](https://goreportcard.com/report/github.com/foomo/keel)
[![godoc](https://godoc.org/github.com/foomo/keel?status.svg)](https://godoc.org/github.com/foomo/keel)
[![GitHub Super-Linter](https://github.com/foomo/keel/workflows/CI/badge.svg)](https://github.com/marketplace/actions/super-linter)
[![Coverage Status](https://coveralls.io/repos/github/foomo/keel/badge.svg?branch=main&)](https://coveralls.io/github/foomo/keel?branch=main)
[![GoDoc](https://godoc.org/github.com/foomo/keel?status.svg)](https://godoc.org/github.com/foomo/keel)

> Opinionated way to run services.
Expand All @@ -25,6 +26,7 @@ import (
"net/http"

"github.com/foomo/keel"
"github.com/foomo/keel/service"
)

func main() {
Expand All @@ -39,7 +41,7 @@ func main() {
svs := newService()

svr.AddService(
keel.NewServiceHTTP(l, "demo", ":8080", svs),
service.NewHTTP(l, "demo", "localhost:8080", svs),
)

svr.Run()
Expand Down
58 changes: 25 additions & 33 deletions closer.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
package keel

import "context"

type closer struct {
handle func(context.Context) error
}

func NewCloserFn(handle func(context.Context) error) closer {
return closer{
handle: handle,
import (
"github.com/foomo/keel/interfaces"
)

func IsCloser(v any) bool {
switch v.(type) {
case interfaces.Closer,
interfaces.ErrorCloser,
interfaces.CloserWithContext,
interfaces.ErrorCloserWithContext,
interfaces.Shutdowner,
interfaces.ErrorShutdowner,
interfaces.ShutdownerWithContext,
interfaces.ErrorShutdownerWithContext,
interfaces.Stopper,
interfaces.ErrorStopper,
interfaces.StopperWithContext,
interfaces.ErrorStopperWithContext,
interfaces.Unsubscriber,
interfaces.ErrorUnsubscriber,
interfaces.UnsubscriberWithContext,
interfaces.ErrorUnsubscriberWithContext:
return true
default:
return false
}
}

func (h healther) Close(ctx context.Context) error {
return h.handle(ctx)
}

// Closer interface
type Closer interface {
Close()
}

// ErrorCloser interface
type ErrorCloser interface {
Close() error
}

// CloserWithContext interface
type CloserWithContext interface {
Close(ctx context.Context)
}

// ErrorCloserWithContext interface
type ErrorCloserWithContext interface {
Close(ctx context.Context) error
}
Loading

0 comments on commit bbd9088

Please sign in to comment.