mirror of
https://github.com/foomo/foomo-docs.git
synced 2025-10-16 12:35:40 +00:00
feat: docs gotsrpc value objects
This commit is contained in:
parent
8450695f68
commit
bedd94b28a
@ -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
|
||||
|
||||
|
||||
@ -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<T>|null` in TypeScript.
|
||||
### Scalar types
|
||||
|
||||
```go
|
||||
[]string
|
||||
[]int
|
||||
// other numeric types
|
||||
[]bool
|
||||
```
|
||||
|
||||
```typescript
|
||||
Array<string>|null
|
||||
Array<number>|null
|
||||
// all numeric types are numbers
|
||||
Array<boolean>|null
|
||||
```
|
||||
|
||||
### Other slice type examples
|
||||
|
||||
|
||||
#### structs
|
||||
```go
|
||||
[]Car
|
||||
[]*Car
|
||||
```
|
||||
|
||||
```typescript
|
||||
Array<Car>|null
|
||||
Array<Car|null>|null
|
||||
```
|
||||
#### nested slices
|
||||
```go
|
||||
[][]string
|
||||
[][]int
|
||||
// ...
|
||||
```
|
||||
|
||||
```typescript
|
||||
Array<Array<string>|null>|null
|
||||
Array<Array<number>|null>|null
|
||||
// ...
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Maps / Records
|
||||
|
||||
Like slices Go maps are nilable. They translate to `Record<K extends keyof any, T>|null` in TypeScript.
|
||||
|
||||
|
||||
### scalars
|
||||
|
||||
```go
|
||||
map[string]string
|
||||
```
|
||||
|
||||
```typescript
|
||||
Record<string,string>|null
|
||||
```
|
||||
|
||||
### structs
|
||||
|
||||
```go
|
||||
map[string]*Car
|
||||
```
|
||||
|
||||
```typescript
|
||||
Record<string,Car|null>|null
|
||||
```
|
||||
|
||||
### slices
|
||||
|
||||
```go
|
||||
map[string][]*Car
|
||||
```
|
||||
|
||||
```typescript
|
||||
Record<string,Array<Car|null>|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<ProductID,Car|null>|null
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
### nested maps
|
||||
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user