-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
136 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,46 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
tags: [ 'v*.*.*' ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
goos: ["linux"] | ||
goarch: ["amd64", "arm64"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: "go.mod" | ||
- name: Build | ||
env: | ||
GOOS: ${{ matrix.goos }} | ||
GOARCH: ${{ matrix.goarch }} | ||
run: go build -o "livebox-cli-${GOOS}-${GOARCH}" cmd/livebox-cli/main.go | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: livebox-cli-${{ matrix.goos }}-${{ matrix.goarch }} | ||
path: livebox-cli-${{ matrix.goos }}-${{ matrix.goarch }} | ||
retention-days: 1 | ||
upload: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
if: startsWith(github.ref, 'refs/tags/') | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
path: artifacts | ||
merge-multiple: true | ||
- name: Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
files: | | ||
artifacts/* |
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
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,63 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/Tomy2e/livebox-api-client" | ||
"github.com/Tomy2e/livebox-api-client/api/request" | ||
) | ||
|
||
func main() { | ||
var ( | ||
service = flag.String("service", "", "service") | ||
method = flag.String("method", "", "method") | ||
params = flag.String("params", "", "JSON-encoded params") | ||
) | ||
flag.Parse() | ||
|
||
client, err := livebox.NewClient(os.Getenv("ADMIN_PASSWORD")) | ||
if err != nil { | ||
log.Fatalf("failed to create livebox client: %s", err) | ||
} | ||
|
||
req, err := newRequest(*service, *method, *params) | ||
if err != nil { | ||
log.Fatalf("failed to create request: %s", err) | ||
} | ||
|
||
out := json.RawMessage{} | ||
if err := client.Request(context.Background(), req, &out); err != nil { | ||
log.Fatalf("request failed: %s", err) | ||
} | ||
|
||
fmt.Println(string(out)) | ||
} | ||
|
||
func newRequest(service, method, params string) (*request.Request, error) { | ||
if service == "" { | ||
return nil, errors.New("-service is missing") | ||
} | ||
|
||
if method == "" { | ||
return nil, errors.New("-method is missing") | ||
} | ||
|
||
var parameters request.Parameters | ||
if params != "" { | ||
if err := json.Unmarshal([]byte(params), ¶meters); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal params: %w", err) | ||
} | ||
} | ||
|
||
return &request.Request{ | ||
Service: service, | ||
Method: method, | ||
Parameters: parameters, | ||
}, nil | ||
} |