Skip to content

Commit

Permalink
implementation of tranport
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur1 committed Jul 12, 2024
1 parent 5257c19 commit 1ee1d15
Show file tree
Hide file tree
Showing 16 changed files with 723 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI for pull request

on:
pull_request:

jobs:
test-go:
strategy:
matrix:
version: [stable, oldstable]
uses: ./.github/workflows/wf-test-go.yml
with:
go-version: ${{ matrix.version }}
29 changes: 29 additions & 0 deletions .github/workflows/on-push-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI for main branch

on:
push:
branches: [main]

jobs:
test-go:
strategy:
matrix:
version: [stable, oldstable]
uses: ./.github/workflows/wf-test-go.yml
with:
go-version: ${{ matrix.version }}

tagpr:
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: 364898
private-key: ${{ secrets.ARTHUR1_BOT_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- uses: Songmu/tagpr@v1
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
35 changes: 35 additions & 0 deletions .github/workflows/wf-test-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: test-go

on:
workflow_call:
inputs:
go-version:
type: string
required: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- uses: golangci/golangci-lint-action@v6
with:
args: --timeout=10m
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- run: |
go install github.com/mfridman/tparse@latest
- run: |
set -o pipefail
go test ./... -cover -json | tee ./go-test.out | tparse -all
- if: always()
run: |
tparse -file ./go-test.out -format markdown >> "$GITHUB_STEP_SUMMARY"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 ASAKURA Kazuki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# http-client-cache
13 changes: 13 additions & 0 deletions cache/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cache

import (
"context"
"net/http"
"time"
)

type CacheEngine interface {
Key(req *http.Request) (key string, err error)
Get(ctx context.Context, key string, req *http.Request) (res *http.Response, ok bool, err error)
Set(ctx context.Context, key string, res *http.Response, expiration time.Duration) error
}
3 changes: 3 additions & 0 deletions cache/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package cache

//go:generate go run go.uber.org/mock/mockgen -source=cache.go -destination=./mock/cache.go
87 changes: 87 additions & 0 deletions cache/mock/cache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/Arthur1/http-client-cache

go 1.21.0

require (
github.com/google/go-cmp v0.6.0
github.com/stretchr/testify v1.9.0
go.uber.org/mock v0.4.0
golang.org/x/sync v0.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/tools v0.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
13 changes: 13 additions & 0 deletions internal/testutil/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package testutil

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
)

func NoDiff(t *testing.T, want, got any, opts []cmp.Option, msgAndArgs ...any) {
t.Helper()
assert.Empty(t, cmp.Diff(got, want, opts...), msgAndArgs...)
}
19 changes: 19 additions & 0 deletions internal/testutil/gomock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package testutil

import (
"log"
"testing"
)

// https://github.com/golang/mock/issues/145
type ConcurrentTestReporter struct {
*testing.T
}

func NewConcurrentTestReporter(t *testing.T) *ConcurrentTestReporter {
return &ConcurrentTestReporter{t}
}

func (r *ConcurrentTestReporter) Fatalf(format string, args ...interface{}) {
log.Fatalf(format, args...)
}
1 change: 1 addition & 0 deletions internal/tools/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package tools
7 changes: 7 additions & 0 deletions internal/tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build tools

package tools

import (
_ "go.uber.org/mock/mockgen"
)
Loading

0 comments on commit 1ee1d15

Please sign in to comment.