From bedd94b28a6e489648a083383adce9ac4c13e5b3 Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Tue, 25 Apr 2023 09:06:07 +0200 Subject: [PATCH] feat: docs gotsrpc value objects --- .../gotsrpc/service-interfaces/index.md | 2 +- .../service-interfaces/value-objects.md | 101 +++++++++++++++++- foomo/docs/projects/gotsrpc/workflow.md | 2 +- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/foomo/docs/projects/gotsrpc/service-interfaces/index.md b/foomo/docs/projects/gotsrpc/service-interfaces/index.md index 26b2611..e795ed3 100644 --- a/foomo/docs/projects/gotsrpc/service-interfaces/index.md +++ b/foomo/docs/projects/gotsrpc/service-interfaces/index.md @@ -1,6 +1,6 @@ # Service Interfaces -`Gotsrpc` services are defined in Go. Visit the [playground](playground) +`Gotsrpc` services are defined in Go. ## Interface definitions and value objects diff --git a/foomo/docs/projects/gotsrpc/service-interfaces/value-objects.md b/foomo/docs/projects/gotsrpc/service-interfaces/value-objects.md index fd38e32..0c1ce7f 100644 --- a/foomo/docs/projects/gotsrpc/service-interfaces/value-objects.md +++ b/foomo/docs/projects/gotsrpc/service-interfaces/value-objects.md @@ -1,5 +1,6 @@ --- sidebar_position: 1 +toc_max_heading_level: 5 --- # Value Objects @@ -86,7 +87,105 @@ interface Car { } ``` -## Slices / Arrays +## Slices + +Slices are nilable in Go, thus they can be null in TypeScript. They translate to `Array|null` in TypeScript. +### Scalar types + +```go +[]string +[]int +// other numeric types +[]bool +``` + +```typescript +Array|null +Array|null +// all numeric types are numbers +Array|null +``` + +### Other slice type examples + + +#### structs +```go +[]Car +[]*Car +``` + +```typescript +Array|null +Array|null +``` +#### nested slices +```go +[][]string +[][]int +// ... +``` + +```typescript +Array|null>|null +Array|null>|null +// ... +``` + + ## Maps / Records +Like slices Go maps are nilable. They translate to `Record|null` in TypeScript. + + +### scalars + +```go +map[string]string +``` + +```typescript +Record|null +``` + +### structs + +```go +map[string]*Car +``` + +```typescript +Record|null +``` + +### slices + +```go +map[string][]*Car +``` + +```typescript +Record|null>|null +``` + +## custom map types + +Go and TypeScript support map / Record types: + +:::note +Scalar types / type aliases are of particular value when using maps, because they can add strong semantics: +::: + +```go +type CarDirectory map[ProductID]*Car +``` + +```typescript +type CarDirectory = Record|null +``` + + + + +### nested maps \ No newline at end of file diff --git a/foomo/docs/projects/gotsrpc/workflow.md b/foomo/docs/projects/gotsrpc/workflow.md index 66ba646..5825cb5 100644 --- a/foomo/docs/projects/gotsrpc/workflow.md +++ b/foomo/docs/projects/gotsrpc/workflow.md @@ -14,5 +14,5 @@ sidebar_position: 3 1. define [service interfaces](service-interfaces) in Go 2. configure code generation in [`gotsrpc.yaml`](cli/gotsrpc.yaml) -3. generate service proxies and client with [`gotsrpc` cli](cli) +3. generate service proxies and clients with [`gotsrpc` cli](cli) 4. go to 1.