Skip to content

Commit

Permalink
story(bedrock): refactor to only contain base package and middleware …
Browse files Browse the repository at this point in the history
…package (#339)
  • Loading branch information
Zaba505 authored Dec 15, 2024
1 parent f985fdb commit fb43aeb
Show file tree
Hide file tree
Showing 89 changed files with 77 additions and 6,783 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5
with:
go-version: '1.22'
go-version: '1.23'

- name: Lint Go Code
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6
Expand All @@ -43,13 +43,4 @@ jobs:
run: go build ./...

- name: Test
run: go test -race -cover ./...

- name: Build example container images
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6
with:
distribution: goreleaser
version: latest
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: go test -race -cover ./...
18 changes: 1 addition & 17 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5
with:
go-version: '1.22'
go-version: '1.23'

- name: Lint Go Code
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6
Expand All @@ -33,19 +33,3 @@ jobs:

- name: Test
run: go test -race -cover ./...

- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build example container images
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
[![Go Reference](https://pkg.go.dev/badge/github.com/z5labs/bedrock.svg)](https://pkg.go.dev/github.com/z5labs/bedrock)
[![Go Report Card](https://goreportcard.com/badge/github.com/z5labs/bedrock)](https://goreportcard.com/report/github.com/z5labs/bedrock)
![Coverage](https://img.shields.io/badge/Coverage-94.2%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-98.6%25-brightgreen)
[![build](https://github.com/z5labs/bedrock/actions/workflows/build.yaml/badge.svg)](https://github.com/z5labs/bedrock/actions/workflows/build.yaml)

**bedrock provides a minimal, modular and composable foundation for
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion bedrock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"errors"
"fmt"

"github.com/z5labs/bedrock/pkg/config"
"github.com/z5labs/bedrock/config"
)

// App represents the entry point for user specific code.
Expand Down
2 changes: 1 addition & 1 deletion bedrock_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"
"strings"

"github.com/z5labs/bedrock/pkg/config"
"github.com/z5labs/bedrock/config"
)

type appFunc func(context.Context) error
Expand Down
2 changes: 1 addition & 1 deletion bedrock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"testing"

"github.com/z5labs/bedrock/pkg/config"
"github.com/z5labs/bedrock/config"

"github.com/stretchr/testify/assert"
)
Expand Down
13 changes: 2 additions & 11 deletions pkg/config/config.go → config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"reflect"
"time"

"github.com/z5labs/bedrock/pkg/config/key"
"github.com/z5labs/bedrock/config/key"

"github.com/go-viper/mapstructure/v2"
)
Expand All @@ -31,7 +31,7 @@ type Source interface {

// Manager
type Manager struct {
store Map
store Store
}

// Read
Expand All @@ -41,10 +41,6 @@ func Read(srcs ...Source) (*Manager, error) {
return &Manager{store: make(Map)}, nil
}

if m, ok := srcs[0].(*Manager); len(srcs) == 1 && ok {
return m, nil
}

store := make(Map)
for _, src := range srcs {
err := src.Apply(store)
Expand All @@ -58,11 +54,6 @@ func Read(srcs ...Source) (*Manager, error) {
return m, nil
}

// Apply implements the [Source] interface.
func (m *Manager) Apply(store Store) error {
return m.store.Apply(store)
}

// Unmarshal
func (m *Manager) Unmarshal(v any) error {
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Expand Down
File renamed without changes.
17 changes: 0 additions & 17 deletions pkg/config/config_test.go → config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,6 @@ func TestRead(t *testing.T) {
}
})
})

t.Run("will be idempotent", func(t *testing.T) {
t.Run("if a single Manager is used as the source", func(t *testing.T) {
m, err := Read(FromYaml(strings.NewReader("hello: world")))
if !assert.Nil(t, err) {
return
}

m2, err := Read(m)
if !assert.Nil(t, err) {
return
}
if !assert.Equal(t, m, m2) {
return
}
})
})
}

type Custom struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions pkg/config/json.go → config/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"fmt"
"io"

"github.com/z5labs/bedrock/pkg/internal/ioutil"
"github.com/z5labs/bedrock/internal/ioutil"
)

// Json represents a Source where its underlying format is JSON.
Expand Down Expand Up @@ -42,7 +42,7 @@ func (e InvalidJsonError) Unwrap() error {

// Apply implements the Source interface.
func (src Json) Apply(store Store) error {
b, err := ioutil.ReadAllAndClose(src.r)
b, err := ioutil.ReadAllAndTryClose(src.r)
if err != nil && !errors.Is(err, ioutil.CloseError{}) {
// We can ignore ioutil.CloseError because we've successfully
// read the file contents and closing is just a nice clean up
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/json_test.go → config/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

"github.com/z5labs/bedrock/pkg/config/key"
"github.com/z5labs/bedrock/config/key"

"github.com/stretchr/testify/assert"
)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/config/map.go → config/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package config
import (
"fmt"

"github.com/z5labs/bedrock/pkg/config/key"
"github.com/z5labs/bedrock/config/key"
)

// Map is an ordinary map[string]any but implements the [Store] and [Source] interfaces.
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/map_test.go → config/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
"testing"

"github.com/z5labs/bedrock/pkg/config/key"
"github.com/z5labs/bedrock/config/key"

"github.com/stretchr/testify/assert"
)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pkg/config/text_template.go → config/text_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"sync"
"text/template"

"github.com/z5labs/bedrock/pkg/internal/ioutil"
"github.com/z5labs/bedrock/internal/ioutil"
)

// RenderTextTemplateOption represents options for configuring the TextTemplateRenderer.
Expand Down Expand Up @@ -98,7 +98,7 @@ func (ttr *TextTemplateRenderer) Read(b []byte) (int, error) {
var err error
ttr.renderOnce.Do(func() {
var sb strings.Builder
_, err = ioutil.CopyAndClose(&sb, ttr.r)
_, err = ioutil.CopyAndTryClose(&sb, ttr.r)
if err != nil && !errors.Is(err, ioutil.CloseError{}) {
// We can ignore ioutil.CloseError because we've successfully
// read the file contents and closing is just a nice clean up
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pkg/config/yaml.go → config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"
"io"

"github.com/z5labs/bedrock/pkg/internal/ioutil"
"github.com/z5labs/bedrock/internal/ioutil"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -43,7 +43,7 @@ func (e InvalidYamlError) Unwrap() error {

// Apply implements the Source interface.
func (src Yaml) Apply(store Store) error {
b, err := ioutil.ReadAllAndClose(src.r)
b, err := ioutil.ReadAllAndTryClose(src.r)
if err != nil && !errors.Is(err, ioutil.CloseError{}) {
// We can ignore ioutil.CloseError because we've successfully
// read the file contents and closing is just a nice clean up
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/yaml_test.go → config/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

"github.com/z5labs/bedrock/pkg/config/key"
"github.com/z5labs/bedrock/config/key"

"github.com/stretchr/testify/assert"
)
Expand Down
11 changes: 0 additions & 11 deletions example/custom_framework/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions example/custom_framework/echo/Containerfile

This file was deleted.

31 changes: 0 additions & 31 deletions example/custom_framework/echo/app/app.go

This file was deleted.

Empty file.
50 changes: 0 additions & 50 deletions example/custom_framework/echo/endpoint/echo.go

This file was deleted.

Loading

0 comments on commit fb43aeb

Please sign in to comment.