diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6edb94b..5a524e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,9 +4,7 @@ on: push: branches: [ main ] pull_request: - branches: [ main ] merge_group: - branches: [ main ] workflow_dispatch: concurrency: @@ -17,6 +15,11 @@ env: GOFLAGS: -mod=readonly GOPROXY: https://proxy.golang.org +permissions: + contents: read + pull-requests: read + checks: write + jobs: test: runs-on: ubuntu-latest @@ -28,10 +31,24 @@ jobs: check-latest: true go-version-file: go.mod + - uses: actions/setup-node@v4 + + - name: Run yarn install + working-directory: example + run: yarn install + + - name: Run go mod tidy + run: | + make tidy + git diff --exit-code + - uses: golangci/golangci-lint-action@v6 - with: - working-directory: ${{ matrix.gomod }} - name: Run tests - run: go test -v ./... + run: make test + + - name: Make examples + run: | + make examples + git diff --exit-code diff --git a/.gitignore b/.gitignore index 76b564e..88561b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,27 @@ -!.git* -/vendor/ -dist/ -.idea +.* bin/ +dist/ tmp/ -**/node_modules/ \ No newline at end of file + +## Git ## +!.gitignore +!.gitkeep + +## GitHub ## +!.github/ + +## Node ## +**/node_modules/ + +## TypeScript ### +*.tsbuildinfo + +## Goreleaser ### +!.goreleaser.yaml + +### Go ### +/go.mod +/go.sum +/go.work +/go.work.sum +!.golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml index 3753413..8429e65 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -52,6 +52,19 @@ linters: - unused # (megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] # Disabled by default linters: + #- canonicalheader # canonicalheader checks whether net/http.Header uses canonical header [fast: false, auto-fix: false] + #- dupword # checks for duplicate words in the source code [fast: true, auto-fix: false] + #- fatcontext # detects nested contexts in loops and function literals [fast: false, auto-fix: false] + #- iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. [fast: false, auto-fix: false] + #- interfacebloat # A linter that checks the number of methods inside an interface. [fast: true, auto-fix: false] + #- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [fast: false, auto-fix: false] + #- reassign # Checks that package variables are not reassigned [fast: false, auto-fix: false] + #- recvcheck # checks for receiver type consistency [fast: false, auto-fix: false] + #- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false] + #- tagalign # check that struct tags are well aligned [fast: true, auto-fix: true] + #- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false] + + - asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false] - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] - bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false] @@ -67,10 +80,8 @@ linters: - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false] - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false] - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false] - - execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds [fast: false, auto-fix: false] - exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false] #- exhaustruct # Checks if all structure fields are initialized [fast: false, auto-fix: false] - - exportloopref # checks for pointers to enclosing loop variables [fast: false, auto-fix: false] #- forbidigo # Forbids identifiers [fast: true, auto-fix: false] - forcetypeassert # finds forced type assertions [fast: true, auto-fix: false] #- funlen # Tool for detection of long functions [fast: true, auto-fix: false] @@ -83,12 +94,12 @@ linters: #- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] #- godot # Check if comments end in a period [fast: true, auto-fix: true] #- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] - #- goerr113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false] + #- err113: Go linter to check the errors handling expressions [fast: false, auto-fix: false] - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] #- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] - goheader # Checks is file header matches to pattern [fast: true, auto-fix: false] - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] - #- gomnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false] + #- mnd: An analyzer to detect magic numbers. [fast: true, auto-fix: false] #- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] - goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] diff --git a/Makefile b/Makefile index c4f4f39..56d4a88 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ test: install: go install cmd/gotsrpc/gotsrpc.go +.PHONY: install.debug ## Run go install with debug install.debug: go install -gcflags "all=-N -l" cmd/gotsrpc/gotsrpc.go @@ -19,6 +20,12 @@ install.debug: outdated: go list -u -m -json all | go-mod-outdated -update -direct +.PHONY: build.debug +## Build binary in debug mode +build.debug: + rm -f bin/gotsrpc + go build -gcflags "all=-N -l" -o bin/gotsrpc cmd/gotsrpc/gotsrpc.go + ## === Tools === EXAMPLES=basic errors monitor nullable union time diff --git a/example/basic/client/src/service-vo.ts b/example/basic/client/src/service-vo.ts index 9e0a900..260a987 100644 --- a/example/basic/client/src/service-vo.ts +++ b/example/basic/client/src/service-vo.ts @@ -1,6 +1,7 @@ /* eslint:disable */ // Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT. import * as github_com_foomo_gotsrpc_v2_example_basic_service from './service-vo'; // ./client/src/service-vo.ts to ./client/src/service-vo.ts + // github.com/foomo/gotsrpc/v2/example/basic/service.Float32Type export enum Float32Type { Float32AType = 1, diff --git a/example/basic/gotsrpc.yml b/example/basic/gotsrpc.yml index e64a9e5..deb2c3e 100644 --- a/example/basic/gotsrpc.yml +++ b/example/basic/gotsrpc.yml @@ -1,6 +1,6 @@ module: - name: github.com/foomo/gotsrpc/v2/example/basic - path: ./ + name: github.com/foomo/gotsrpc/v2 + path: ../../ targets: basic: diff --git a/example/errors/client/src/service-vo.ts b/example/errors/client/src/service-vo.ts index 7d8988a..bd5fb2d 100644 --- a/example/errors/client/src/service-vo.ts +++ b/example/errors/client/src/service-vo.ts @@ -1,8 +1,10 @@ /* eslint:disable */ // Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT. import * as github_com_foomo_gotsrpc_v2_example_errors_service_frontend from './service-vo'; // ./client/src/service-vo.ts to ./client/src/service-vo.ts + // github.com/foomo/gotsrpc/v2/example/errors/service/frontend.ErrMulti -export type ErrMulti = (typeof github_com_foomo_gotsrpc_v2_example_errors_service_frontend.ErrMultiA) & (typeof github_com_foomo_gotsrpc_v2_example_errors_service_frontend.ErrMultiB) +export const ErrMulti = { ...github_com_foomo_gotsrpc_v2_example_errors_service_frontend.ErrMultiA, ...github_com_foomo_gotsrpc_v2_example_errors_service_frontend.ErrMultiB } +export type ErrMulti = typeof ErrMulti // github.com/foomo/gotsrpc/v2/example/errors/service/frontend.ErrMultiA export enum ErrMultiA { One = "one", diff --git a/example/errors/gotsrpc.yml b/example/errors/gotsrpc.yml index 3f1ebbd..5847e69 100644 --- a/example/errors/gotsrpc.yml +++ b/example/errors/gotsrpc.yml @@ -1,6 +1,6 @@ module: - name: github.com/foomo/gotsrpc/v2/example/errors - path: ./ + name: github.com/foomo/gotsrpc/v2 + path: ../../ targets: frontend: diff --git a/example/errors/handler/backend/handler.go b/example/errors/handler/backend/handler.go index ed40914..31443d1 100644 --- a/example/errors/handler/backend/handler.go +++ b/example/errors/handler/backend/handler.go @@ -21,8 +21,8 @@ type ( ) const ( - ScalarErrorOne ScalarError = "scalar error one" //nolint:errname - ScalarErrorTwo ScalarError = "scalar error two" //nolint:errname + ScalarErrorOne ScalarError = "scalar error one" + ScalarErrorTwo ScalarError = "scalar error two" ) func NewScalarError(e ScalarError) *ScalarError { diff --git a/example/errors/service/backend/service.go b/example/errors/service/backend/service.go index 7815237..7fe19bf 100644 --- a/example/errors/service/backend/service.go +++ b/example/errors/service/backend/service.go @@ -39,8 +39,8 @@ type ( ) const ( - ScalarOne ScalarError = "one" //nolint:errname - ScalarTwo ScalarError = "two" //nolint:errname + ScalarOne ScalarError = "one" + ScalarTwo ScalarError = "two" ScalarAOne ScalarA = "one" ScalarATwo ScalarA = "two" diff --git a/example/monitor/gotsrpc.yml b/example/monitor/gotsrpc.yml index ea4fbcd..cce5401 100644 --- a/example/monitor/gotsrpc.yml +++ b/example/monitor/gotsrpc.yml @@ -1,6 +1,6 @@ module: - name: github.com/foomo/gotsrpc/v2/example/monitor - path: ./ + name: github.com/foomo/gotsrpc/v2 + path: ../../ targets: monitor: diff --git a/example/nullable/client/src/service-vo.ts b/example/nullable/client/src/service-vo.ts index 35504d5..70e1b15 100644 --- a/example/nullable/client/src/service-vo.ts +++ b/example/nullable/client/src/service-vo.ts @@ -1,6 +1,7 @@ /* eslint:disable */ // Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT. import * as github_com_foomo_gotsrpc_v2_example_nullable_service from './service-vo'; // ./client/src/service-vo.ts to ./client/src/service-vo.ts + // github.com/foomo/gotsrpc/v2/example/nullable/service.ACustomType export enum ACustomType { One = "one", diff --git a/example/nullable/gotsrpc.yml b/example/nullable/gotsrpc.yml index 52963ed..309143c 100644 --- a/example/nullable/gotsrpc.yml +++ b/example/nullable/gotsrpc.yml @@ -1,6 +1,6 @@ module: - name: github.com/foomo/gotsrpc/v2/example/nullable - path: ./ + name: github.com/foomo/gotsrpc/v2 + path: ../../ targets: nullable: diff --git a/example/package.json b/example/package.json index defd640..ef508af 100644 --- a/example/package.json +++ b/example/package.json @@ -3,6 +3,6 @@ "version": "0.1.0", "name": "@foomo/gotsrpc-examples", "devDependencies": { - "typescript": "^4.6.2" + "typescript": "5.6.3" } } diff --git a/example/time/client/src/service-client.ts b/example/time/client/src/service-client.ts index be01655..2d9f803 100644 --- a/example/time/client/src/service-client.ts +++ b/example/time/client/src/service-client.ts @@ -1,7 +1,6 @@ /* eslint:disable */ // Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT. import * as github_com_foomo_gotsrpc_v2_example_time_service from './service-vo-service'; // ./client/src/service-client.ts to ./client/src/service-vo-service.ts -import * as time from './service-vo-time'; // ./client/src/service-client.ts to ./client/src/service-vo-time.ts export class ServiceClient { public static defaultEndpoint = "/service"; diff --git a/example/time/client/src/service-vo-service.ts b/example/time/client/src/service-vo-service.ts index a3fdbde..ac60638 100644 --- a/example/time/client/src/service-vo-service.ts +++ b/example/time/client/src/service-vo-service.ts @@ -1,7 +1,6 @@ /* eslint:disable */ // Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT. -import * as github_com_foomo_gotsrpc_v2_example_time_service from './service-vo-service'; // ./client/src/service-vo-service.ts to ./client/src/service-vo-service.ts -import * as time from './service-vo-time'; // ./client/src/service-vo-service.ts to ./client/src/service-vo-time.ts + // github.com/foomo/gotsrpc/v2/example/time/service.TimeStruct export interface TimeStruct { time:number; diff --git a/example/time/client/src/service-vo-time.ts b/example/time/client/src/service-vo-time.ts index e771808..ad43eae 100644 --- a/example/time/client/src/service-vo-time.ts +++ b/example/time/client/src/service-vo-time.ts @@ -1,7 +1,7 @@ /* eslint:disable */ // Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT. -import * as github_com_foomo_gotsrpc_v2_example_time_service from './service-vo-service'; // ./client/src/service-vo-time.ts to ./client/src/service-vo-service.ts import * as time from './service-vo-time'; // ./client/src/service-vo-time.ts to ./client/src/service-vo-time.ts + // time.Time export interface Time { } diff --git a/example/time/gotsrpc.yml b/example/time/gotsrpc.yml index 40e6a7e..9f3bf06 100644 --- a/example/time/gotsrpc.yml +++ b/example/time/gotsrpc.yml @@ -1,6 +1,6 @@ module: - name: github.com/foomo/gotsrpc/v2/example/time - path: ./ + name: github.com/foomo/gotsrpc/v2 + path: ../../ targets: time: diff --git a/example/union/client/src/app.ts b/example/union/client/src/app.ts index 76db3c4..81cd79d 100644 --- a/example/union/client/src/app.ts +++ b/example/union/client/src/app.ts @@ -47,4 +47,4 @@ function assertExhaustive( message: string = 'msg' ): never { throw new Error(message); -} \ No newline at end of file +} diff --git a/example/union/client/src/service-vo.ts b/example/union/client/src/service-vo.ts index fd268f7..f198091 100644 --- a/example/union/client/src/service-vo.ts +++ b/example/union/client/src/service-vo.ts @@ -1,6 +1,7 @@ /* eslint:disable */ // Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT. import * as github_com_foomo_gotsrpc_v2_example_union_service from './service-vo'; // ./client/src/service-vo.ts to ./client/src/service-vo.ts + // github.com/foomo/gotsrpc/v2/example/union/service.InlineStruct export interface InlineStruct extends github_com_foomo_gotsrpc_v2_example_union_service.InlineStructA , github_com_foomo_gotsrpc_v2_example_union_service.InlineStructB { value:string; @@ -19,7 +20,8 @@ export interface InlineStructPtr extends Partial