Skip to content

Commit 3555a06

Browse files
committed
first commit
0 parents  commit 3555a06

17 files changed

+4802
-0
lines changed

.github/workflows/release.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches:
6+
- "!**/*"
7+
tags:
8+
- "v*"
9+
workflow_dispatch:
10+
inputs:
11+
tag:
12+
description: "release tag"
13+
required: true
14+
type: string
15+
16+
jobs:
17+
goreleaser:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
with:
23+
ref: ${{ inputs.tag || github.ref }}
24+
- name: Set up Go
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: "1.21"
28+
- name: Run GoReleaser
29+
uses: goreleaser/goreleaser-action@v1
30+
with:
31+
version: latest
32+
args: release
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tagpr.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: tagpr
2+
on:
3+
push:
4+
branches: ["main"]
5+
jobs:
6+
deploy:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: Songmu/tagpr@main
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Go
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
strategy:
6+
matrix:
7+
go:
8+
- '1.20'
9+
- '1.21'
10+
name: Build
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: ${{ matrix.go }}
18+
id: go
19+
20+
- name: Check out code into the Go module directory
21+
uses: actions/checkout@v3
22+
23+
- name: Build & Test
24+
run: |
25+
go test -race ./...
26+
env:
27+
GO111MODULE: on

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
.envrc

.goreleaser.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
main: cmd/aws-sdk-client-go/main.go
8+
binary: aws-sdk-client-go
9+
goos:
10+
- linux
11+
- darwin
12+
- windows
13+
goarch:
14+
- amd64
15+
- arm64
16+
checksum:
17+
name_template: "checksums.txt"
18+
snapshot:
19+
name_template: "{{ .Tag }}-next"
20+
changelog:
21+
sort: asc
22+
filters:
23+
exclude:
24+
- "^docs:"
25+
- "^test:"

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 FUJIWARA Shunichiro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: clean test
2+
3+
aws-sdk-client-go: go.* *.go gen
4+
go build -o $@ cmd/aws-sdk-client-go/main.go
5+
6+
gen:
7+
go run cmd/aws-sdk-client-gen/main.go
8+
go fmt .
9+
10+
clean:
11+
rm -rf *_gen.go aws-sdk-client-go dist/
12+
13+
test:
14+
go test -v ./...
15+
16+
install:
17+
go install github.com/fujiwara/aws-sdk-client-go/cmd/aws-sdk-client-go
18+
19+
dist:
20+
goreleaser build --snapshot --rm-dist

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# {{ .Project.Name }}
2+
3+
{{ .Project.Description }}
4+
5+
## Usage
6+
7+
aws-sdk-client-go
8+
9+
## LICENSE
10+
11+
{{ .Project.License }}
12+
13+
## Author
14+
15+
{{ .Project.Author.Name }} <{{ .Project.Author.Email }}>

cmd/aws-sdk-client-gen/main.go

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"reflect"
8+
"strings"
9+
10+
"github.com/aws/aws-sdk-go-v2/service/ecs"
11+
"github.com/aws/aws-sdk-go-v2/service/firehose"
12+
"github.com/aws/aws-sdk-go-v2/service/kinesis"
13+
"github.com/aws/aws-sdk-go-v2/service/ssm"
14+
)
15+
16+
func main() {
17+
gen("kinesis", reflect.TypeOf(kinesis.New(kinesis.Options{})))
18+
gen("firehose", reflect.TypeOf(firehose.New(firehose.Options{})))
19+
gen("ssm", reflect.TypeOf(ssm.New(ssm.Options{})))
20+
gen("ecs", reflect.TypeOf(ecs.New(ecs.Options{})))
21+
}
22+
23+
func gen(pkgName string, clientType reflect.Type) error {
24+
buf := &strings.Builder{}
25+
fmt.Fprintln(buf, "package sdkclient")
26+
fmt.Fprintln(buf)
27+
fmt.Fprintf(buf, `import (
28+
"context"
29+
"encoding/json"
30+
"fmt"
31+
"github.com/aws/aws-sdk-go-v2/service/%s"
32+
)
33+
`, pkgName)
34+
var methodNames []string
35+
for i := 0; i < clientType.NumMethod(); i++ {
36+
method := clientType.Method(i)
37+
params := make([]string, 0)
38+
for j := 0; j < method.Type.NumIn(); j++ {
39+
params = append(params, method.Type.In(j).String())
40+
}
41+
if len(params) <= 1 {
42+
log.Printf("no params func %s", method.Name)
43+
continue
44+
}
45+
methodNames = append(methodNames, method.Name)
46+
47+
fmt.Fprintf(buf, `func %s_%s(ctx context.Context, b json.RawMessage) (json.RawMessage, error) {
48+
svc := %s.NewFromConfig(awsCfg)
49+
var in %s
50+
if err := json.Unmarshal(b, &in); err != nil {
51+
return nil, fmt.Errorf("failed to unmarshal request: %%w", err)
52+
}
53+
if out, err := svc.%s(ctx, &in); err != nil {
54+
return nil, fmt.Errorf("failed to call %s: %%w", err)
55+
} else {
56+
o, err := json.Marshal(out)
57+
if err != nil {
58+
return nil, fmt.Errorf("failed to marshal response: %%w", err)
59+
}
60+
return o, nil
61+
}
62+
}
63+
`,
64+
pkgName,
65+
method.Name,
66+
pkgName,
67+
strings.TrimPrefix(params[2], "*"), // (receiver, context.Context, *Request, ...)
68+
method.Name,
69+
method.Name,
70+
)
71+
fmt.Fprintln(buf)
72+
}
73+
fmt.Fprintln(buf, `func init() {`)
74+
for _, name := range methodNames {
75+
fmt.Fprintf(buf, `clientMethods["%s_%s"] = %s_%s
76+
`, pkgName, name, pkgName, name)
77+
}
78+
fmt.Fprintln(buf, "}")
79+
f, err := os.OpenFile(pkgName+"_gen.go", os.O_CREATE|os.O_WRONLY, 0644)
80+
if err != nil {
81+
return err
82+
}
83+
defer f.Close()
84+
if _, err := f.WriteString(buf.String()); err != nil {
85+
return err
86+
}
87+
log.Printf("generated %s_gen.go", pkgName)
88+
return nil
89+
}

cmd/aws-sdk-client-go/main.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
app "github.com/fujiwara/aws-sdk-client-go"
8+
)
9+
10+
func main() {
11+
ctx := context.TODO()
12+
if err := run(ctx); err != nil {
13+
log.Fatal(err)
14+
}
15+
}
16+
17+
func run(ctx context.Context) error {
18+
return app.Run(ctx)
19+
}

0 commit comments

Comments
 (0)