-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3555a06
Showing
17 changed files
with
4,802 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
branches: | ||
- "!**/*" | ||
tags: | ||
- "v*" | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: "release tag" | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.tag || github.ref }} | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.21" | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v1 | ||
with: | ||
version: latest | ||
args: release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: tagpr | ||
on: | ||
push: | ||
branches: ["main"] | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: Songmu/tagpr@main | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Go | ||
on: [push, pull_request] | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go: | ||
- '1.20' | ||
- '1.21' | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build & Test | ||
run: | | ||
go test -race ./... | ||
env: | ||
GO111MODULE: on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
before: | ||
hooks: | ||
- go mod download | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
main: cmd/aws-sdk-client-go/main.go | ||
binary: aws-sdk-client-go | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
checksum: | ||
name_template: "checksums.txt" | ||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 FUJIWARA Shunichiro | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.PHONY: clean test | ||
|
||
aws-sdk-client-go: go.* *.go gen | ||
go build -o $@ cmd/aws-sdk-client-go/main.go | ||
|
||
gen: | ||
go run cmd/aws-sdk-client-gen/main.go | ||
go fmt . | ||
|
||
clean: | ||
rm -rf *_gen.go aws-sdk-client-go dist/ | ||
|
||
test: | ||
go test -v ./... | ||
|
||
install: | ||
go install github.com/fujiwara/aws-sdk-client-go/cmd/aws-sdk-client-go | ||
|
||
dist: | ||
goreleaser build --snapshot --rm-dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# {{ .Project.Name }} | ||
|
||
{{ .Project.Description }} | ||
|
||
## Usage | ||
|
||
aws-sdk-client-go | ||
|
||
## LICENSE | ||
|
||
{{ .Project.License }} | ||
|
||
## Author | ||
|
||
{{ .Project.Author.Name }} <{{ .Project.Author.Email }}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/ecs" | ||
"github.com/aws/aws-sdk-go-v2/service/firehose" | ||
"github.com/aws/aws-sdk-go-v2/service/kinesis" | ||
"github.com/aws/aws-sdk-go-v2/service/ssm" | ||
) | ||
|
||
func main() { | ||
gen("kinesis", reflect.TypeOf(kinesis.New(kinesis.Options{}))) | ||
gen("firehose", reflect.TypeOf(firehose.New(firehose.Options{}))) | ||
gen("ssm", reflect.TypeOf(ssm.New(ssm.Options{}))) | ||
gen("ecs", reflect.TypeOf(ecs.New(ecs.Options{}))) | ||
} | ||
|
||
func gen(pkgName string, clientType reflect.Type) error { | ||
buf := &strings.Builder{} | ||
fmt.Fprintln(buf, "package sdkclient") | ||
fmt.Fprintln(buf) | ||
fmt.Fprintf(buf, `import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/aws/aws-sdk-go-v2/service/%s" | ||
) | ||
`, pkgName) | ||
var methodNames []string | ||
for i := 0; i < clientType.NumMethod(); i++ { | ||
method := clientType.Method(i) | ||
params := make([]string, 0) | ||
for j := 0; j < method.Type.NumIn(); j++ { | ||
params = append(params, method.Type.In(j).String()) | ||
} | ||
if len(params) <= 1 { | ||
log.Printf("no params func %s", method.Name) | ||
continue | ||
} | ||
methodNames = append(methodNames, method.Name) | ||
|
||
fmt.Fprintf(buf, `func %s_%s(ctx context.Context, b json.RawMessage) (json.RawMessage, error) { | ||
svc := %s.NewFromConfig(awsCfg) | ||
var in %s | ||
if err := json.Unmarshal(b, &in); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal request: %%w", err) | ||
} | ||
if out, err := svc.%s(ctx, &in); err != nil { | ||
return nil, fmt.Errorf("failed to call %s: %%w", err) | ||
} else { | ||
o, err := json.Marshal(out) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal response: %%w", err) | ||
} | ||
return o, nil | ||
} | ||
} | ||
`, | ||
pkgName, | ||
method.Name, | ||
pkgName, | ||
strings.TrimPrefix(params[2], "*"), // (receiver, context.Context, *Request, ...) | ||
method.Name, | ||
method.Name, | ||
) | ||
fmt.Fprintln(buf) | ||
} | ||
fmt.Fprintln(buf, `func init() {`) | ||
for _, name := range methodNames { | ||
fmt.Fprintf(buf, `clientMethods["%s_%s"] = %s_%s | ||
`, pkgName, name, pkgName, name) | ||
} | ||
fmt.Fprintln(buf, "}") | ||
f, err := os.OpenFile(pkgName+"_gen.go", os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
if _, err := f.WriteString(buf.String()); err != nil { | ||
return err | ||
} | ||
log.Printf("generated %s_gen.go", pkgName) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
app "github.com/fujiwara/aws-sdk-client-go" | ||
) | ||
|
||
func main() { | ||
ctx := context.TODO() | ||
if err := run(ctx); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func run(ctx context.Context) error { | ||
return app.Run(ctx) | ||
} |
Oops, something went wrong.