mirror of
https://github.com/foomo/foomo-docs.git
synced 2025-10-16 12:35:40 +00:00
261 lines
26 KiB
HTML
261 lines
26 KiB
HTML
<!doctype html>
|
|
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-projects/gotsrpc/service-interfaces/value-objects" data-has-hydrated="false">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="generator" content="Docusaurus v3.0.0">
|
|
<title data-rh="true">Value Objects | foomo project docs</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://www.foomo.org/docs/projects/gotsrpc/service-interfaces/value-objects"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="Value Objects | foomo project docs"><meta data-rh="true" name="description" content="Typically value objects will be serialized / marshalled as JSON. Please refer to this documentation:"><meta data-rh="true" property="og:description" content="Typically value objects will be serialized / marshalled as JSON. Please refer to this documentation:"><link data-rh="true" rel="icon" href="/img/favicon.ico"><link data-rh="true" rel="canonical" href="https://www.foomo.org/docs/projects/gotsrpc/service-interfaces/value-objects"><link data-rh="true" rel="alternate" href="https://www.foomo.org/docs/projects/gotsrpc/service-interfaces/value-objects" hreflang="en"><link data-rh="true" rel="alternate" href="https://www.foomo.org/docs/projects/gotsrpc/service-interfaces/value-objects" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://SUATUVZDDM-dsn.algolia.net" crossorigin="anonymous"><link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="foomo project docs RSS Feed">
|
|
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="foomo project docs Atom Feed">
|
|
|
|
|
|
|
|
<link rel="search" type="application/opensearchdescription+xml" title="foomo project docs" href="/opensearch.xml"><link rel="stylesheet" href="/assets/css/styles.78fe5ce6.css">
|
|
<script src="/assets/js/runtime~main.638e5c2c.js" defer="defer"></script>
|
|
<script src="/assets/js/main.1248442c.js" defer="defer"></script>
|
|
</head>
|
|
<body class="navigation-with-keyboard">
|
|
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><b class="navbar__title text--truncate">foomo</b></a><a class="navbar__item navbar__link" href="/docs/general">General</a><a class="navbar__item navbar__link" href="/docs/frontend">Frontend</a><a class="navbar__item navbar__link" href="/docs/backend">Backend</a><a class="navbar__item navbar__link" href="/docs/devops">DevOps</a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/projects">Projects</a></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link" href="/blog">Blog</a><div class="navbarSearchContainer_Bca1"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><div class="docsWrapper_hBAB"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docRoot_UBD9"><aside class="theme-doc-sidebar-container docSidebarContainer_YfHR"><div class="sidebarViewport_aRkj"><div class="sidebar_njMd"><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects">Overview</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/architecture">Architecture</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/docs/projects/cms">CMS</a><button aria-label="Expand sidebar category 'CMS'" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/gograpple">gograpple</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--active" aria-expanded="true" href="/docs/projects/gotsrpc">gotsrpc</a><button aria-label="Collapse sidebar category 'gotsrpc'" type="button" class="clean-btn menu__caret"></button></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/gotsrpc/getting-started">Getting started</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/docs/projects/gotsrpc/cli">cli</a><button aria-label="Expand sidebar category 'cli'" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/gotsrpc/workflow">Workflow</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--active" aria-expanded="true" tabindex="0" href="/docs/projects/gotsrpc/service-interfaces">Service Interfaces</a><button aria-label="Collapse sidebar category 'Service Interfaces'" type="button" class="clean-btn menu__caret"></button></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link menu__link--active" aria-current="page" tabindex="0" href="/docs/projects/gotsrpc/service-interfaces/value-objects">Value Objects</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/gotsrpc/service-interfaces/errors">Errors</a></li></ul></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/gotsrpc/client-transport">TypeScript client transport</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/docs/projects/gotsrpc/playground">Playground</a><button aria-label="Expand sidebar category 'Playground'" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/gotsrpc/protocol">Protocol</a></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/docs/projects/keel">keel</a><button aria-label="Expand sidebar category 'keel'" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/pagespeed-exporter">pagespeed exporter</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/webgrapple">webgrapple</a></li></ul></nav></div></div></aside><main class="docMainContainer_TBSr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_VOVn"><div class="docItemContainer_Djhp"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label="Breadcrumbs"><ul class="breadcrumbs" itemscope="" itemtype="https://schema.org/BreadcrumbList"><li class="breadcrumbs__item"><a aria-label="Home page" class="breadcrumbs__link" href="/"><svg viewBox="0 0 24 24" class="breadcrumbHomeIcon_YNFT"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item"><a class="breadcrumbs__link" itemprop="item" href="/docs/projects/gotsrpc"><span itemprop="name">gotsrpc</span></a><meta itemprop="position" content="1"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item"><a class="breadcrumbs__link" itemprop="item" href="/docs/projects/gotsrpc/service-interfaces"><span itemprop="name">Service Interfaces</span></a><meta itemprop="position" content="2"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link" itemprop="name">Value Objects</span><meta itemprop="position" content="3"></li></ul></nav><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><h1 id="value-objects">Value Objects</h1>
|
|
<p>Typically value objects will be serialized / marshalled as JSON. Please refer to this documentation:</p>
|
|
<p><a href="https://pkg.go.dev/encoding/json#Marshal">https://pkg.go.dev/encoding/json#Marshal</a></p>
|
|
<admonition type="note"><p>This is just a few basic examples, that show the basics of mapping Go types to idiomatic TypeScript types.</p></admonition>
|
|
<h2 id="scalar-types">Scalar types</h2>
|
|
<h3 id="supported-in-go-and-typescript">Supported in Go and TypeScript</h3>
|
|
<table><thead><tr><th>Go</th><th>TypeScript</th></tr></thead><tbody><tr><td>string</td><td>string</td></tr><tr><td>bool</td><td>boolean</td></tr></tbody></table>
|
|
<h3 id="numerics--numbers">Numerics / numbers</h3>
|
|
<table><thead><tr><th>Go</th><th>TypeScript</th></tr></thead><tbody><tr><td>int, int8, int16, float32, float64 ...</td><td>number</td></tr></tbody></table>
|
|
<h3 id="type-aliases">Type Aliases</h3>
|
|
<pre><code class="language-go" metastring="title="Go"">type Greeting string
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">type Greeting = string;
|
|
</code></pre>
|
|
<h2 id="enumerations">Enumerations</h2>
|
|
<p>Go does not support enumerations, but <code>gotsrpc</code> will translate constants to TypeScripts enums:</p>
|
|
<pre><code class="language-go" metastring="title="Go"">type Pet string
|
|
|
|
const (
|
|
Cat Pet = "cat"
|
|
Dog Pet = "dog"
|
|
Fish Pet = "fish"
|
|
)
|
|
|
|
type SeatCount int
|
|
|
|
const (
|
|
TwoSeats SeatCount = 2
|
|
FiveSeats SeatCount = 5
|
|
SevenSeats SeatCount = 7
|
|
)
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">export enum Pet {
|
|
Cat = "cat",
|
|
Dog = "dog",
|
|
Fish = "fish",
|
|
}
|
|
|
|
export enum SeatCount {
|
|
FiveSeats = 5,
|
|
SevenSeats = 7,
|
|
TwoSeats = 2,
|
|
}
|
|
</code></pre>
|
|
<h2 id="slices">Slices</h2>
|
|
<p>Slices are nilable in Go, thus they can be null in TypeScript. They translate to <code>Array<T>|null</code> in TypeScript.</p>
|
|
<h3 id="scalar-types-1">Scalar types</h3>
|
|
<pre><code class="language-go" metastring="title="Go"">[]string
|
|
[]int
|
|
// other numeric types
|
|
[]bool
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">Array<string> | null;
|
|
Array<number> | null;
|
|
// all numeric types are numbers
|
|
Array<boolean> | null;
|
|
</code></pre>
|
|
<h3 id="other-slice-type-examples">Other slice type examples</h3>
|
|
<h4 id="structs">Structs</h4>
|
|
<pre><code class="language-go" metastring="title="Go"">[]Car
|
|
[]*Car
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">Array<Car> | null;
|
|
Array<Car | null> | null;
|
|
</code></pre>
|
|
<h4 id="nested-slices">Nested slices</h4>
|
|
<pre><code class="language-go" metastring="title="Go"">[][]string
|
|
[][]int
|
|
// ...
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">Array<Array<string> | null> | null;
|
|
Array<Array<number> | null> | null;
|
|
// ...
|
|
</code></pre>
|
|
<h2 id="maps--records">Maps / Records</h2>
|
|
<p>Like slices Go maps are nilable. They translate to <code>Record<K extends keyof any, T>|null</code> in TypeScript.</p>
|
|
<h3 id="scalars">Scalars</h3>
|
|
<pre><code class="language-go" metastring="title="Go"">map[string]string
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">Record<string, string> | null;
|
|
</code></pre>
|
|
<h3 id="structs-1">Structs</h3>
|
|
<pre><code class="language-go" metastring="title="Go"">map[string]*Car
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">Record<string, Car | null> | null;
|
|
</code></pre>
|
|
<h3 id="slices-1">Slices</h3>
|
|
<pre><code class="language-go" metastring="title="Go"">map[string][]*Car
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">Record<string, Array<Car | null> | null> | null;
|
|
</code></pre>
|
|
<h2 id="map-types">Map types</h2>
|
|
<p>Go and TypeScript support map / Record types:</p>
|
|
<admonition type="tip"><p>Scalar types / type aliases are of particular value when using maps, because they can add strong semantics:</p></admonition>
|
|
<pre><code class="language-go" metastring="title="Go"">type CarDirectory map[ProductID]*Car
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">type CarDirectory = Record<ProductID, Car | null> | null;
|
|
</code></pre>
|
|
<h2 id="nested-map-types">Nested map types</h2>
|
|
<pre><code class="language-go" metastring="title="Go"">type BrandID string
|
|
type BrandCarDirectory map[BrandID]map[ProductID]*Car
|
|
// or
|
|
type BrandCarDirectory map[BrandID]CarDirectory
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">type BrandID = string;
|
|
type BrandCarDirectory = Record<
|
|
BrandID,
|
|
Record<ProductID, Car | null> | null
|
|
> | null;
|
|
// or
|
|
type BrandCarDirectory = Record<BrandID, CarDirectory> | null;
|
|
</code></pre>
|
|
<h2 id="structs--interfaces">Structs / Interfaces</h2>
|
|
<p>Arbitrary Types can be composed in structs.</p>
|
|
<h3 id="field-names">Field names</h3>
|
|
<p>Naming conventions are different between Go and TypeScript. In order to bridge the gap between Go and TypeScript Go struct fields can be <a href="https://pkg.go.dev/encoding/json#Marshal">annotated with tags</a>. In this way idiomatic naming of fields can be can be provided for both languages and the translation will be automatic.</p>
|
|
<h4 id="default-go--typescript">Default Go => TypeScript</h4>
|
|
<p>Without json tags TypeScript field names will be like in Go, which is not idiomatic for TypeScript.</p>
|
|
<pre><code class="language-go" metastring="title="Go"">type Car struct {
|
|
GoCase string
|
|
CamelCase string
|
|
SnakeCase string
|
|
}
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">interface Car {
|
|
GoCase:string;
|
|
CamelCase:string;
|
|
SnakeCase:string;
|
|
}
|
|
</code></pre>
|
|
<h4 id="idiomatic-field-names">Idiomatic field names</h4>
|
|
<p>Json tags allow controlling the name in TypeScript.</p>
|
|
<pre><code class="language-go" metastring="title="Go"">type Car struct {
|
|
CamelCase string `json:"camelCase"`
|
|
SnakeCase string `json:"snake_case"`
|
|
}
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">interface Car {
|
|
camelCase:string;
|
|
snake_case:string;
|
|
}
|
|
</code></pre>
|
|
<h3 id="optional-and-nullable-fields">Optional and nullable fields</h3>
|
|
<pre><code class="language-go" metastring="title="Go"">type Basic struct {
|
|
Value string `json:"value"`
|
|
OptionalValue string `json:"optionalValue,omitempty"`
|
|
NullableValue *string `json:"nullableValue"`
|
|
}
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">type Basic interface {
|
|
value:string;
|
|
optionalValue?:string;
|
|
nullableValue:string|null;
|
|
}
|
|
</code></pre>
|
|
<h3 id="hiding-values-from-the-client">Hiding values from the client</h3>
|
|
<p>The Go json tag <code>`json:"-"`</code> on a struct allows it to:</p>
|
|
<ul>
|
|
<li>hide fields from clients</li>
|
|
<li>prevents clients from setting them in JSON Unmarshalling</li>
|
|
</ul>
|
|
<pre><code class="language-go" metastring="title="Go"">type Basic struct {
|
|
Value string `json:"value"`
|
|
Secret string `json:"-"`
|
|
}
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">type Basic interface {
|
|
value:string;
|
|
}
|
|
</code></pre>
|
|
<h3 id="union-types">Union Types</h3>
|
|
<p>When static types seem to be in the way</p>
|
|
<h4 id="scalars-1">Scalars</h4>
|
|
<pre><code class="language-go" metastring="title="Go"">type (
|
|
Species struct {
|
|
LandAnimals *LandAnimals `json:"landAnimals,omitempty" gotsrpc:"union"`
|
|
WaterAnimals *WaterAnimals `json:"waterAnimals,omitempty" gotsrpc:"union"`
|
|
}
|
|
LandAnimals string
|
|
WaterAnimals string
|
|
)
|
|
|
|
const (
|
|
Cat LandAnimals = "cat"
|
|
Dog LandAnimals = "dog"
|
|
)
|
|
|
|
const (
|
|
Catfish WaterAnimals = "catfish"
|
|
Dogfish WaterAnimals = "dogfish"
|
|
)
|
|
)
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">export enum WaterAnimals {
|
|
Catfish = "catfish",
|
|
Dogfish = "dogfish",
|
|
}
|
|
|
|
export enum LandAnimals {
|
|
Cat = "cat",
|
|
Dog = "dog",
|
|
}
|
|
|
|
export const Species = { ...github_com_foomo_gotsrpc_playground_server_services_wof.LandAnimals, ...github_com_foomo_gotsrpc_playground_server_services_wof.WaterAnimals }
|
|
export type Species = github_com_foomo_gotsrpc_playground_server_services_wof.LandAnimals | github_com_foomo_gotsrpc_playground_server_services_wof.WaterAnimals
|
|
</code></pre>
|
|
<h4 id="structs-2">Structs</h4>
|
|
<pre><code class="language-go" metastring="title="Go"">type (
|
|
Trip struct {
|
|
Kind string `json:"kind" gotsrpc:"type:'Trip'"`
|
|
Destination string `json:"destination"`
|
|
}
|
|
Car struct {
|
|
Kind string `json:"kind" gotsrpc:"type:'Car'"`
|
|
Model string `json:"model"`
|
|
}
|
|
Pet struct {
|
|
Kind string `json:"kind" gotsrpc:"type:'Pet'"`
|
|
Name string `json:"name"`
|
|
}
|
|
Price struct {
|
|
Trip *Trip `json:"trip,omitempty" gotsrpc:"union"`
|
|
Car *Car `json:"car,omitempty" gotsrpc:"union"`
|
|
Pet *Pet `json:"pet,omitempty" gotsrpc:"union"`
|
|
}
|
|
)
|
|
</code></pre>
|
|
<pre><code class="language-typescript" metastring="title="TypeScript"">export interface Trip {
|
|
kind:'Trip';
|
|
destination:string;
|
|
}
|
|
|
|
export interface Car {
|
|
kind:'Car';
|
|
model:string;
|
|
}
|
|
|
|
export interface Pet {
|
|
kind:'Pet';
|
|
name:string;
|
|
}
|
|
|
|
export type Price = github_com_foomo_gotsrpc_playground_server_services_wof.Trip | github_com_foomo_gotsrpc_playground_server_services_wof.Car | github_com_foomo_gotsrpc_playground_server_services_wof.Pet | undefined
|
|
</code></pre></div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/foomo/foomo-docs/tree/main/foomo/docs/projects/gotsrpc/service-interfaces/value-objects.md" target="_blank" rel="noopener noreferrer" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col lastUpdated_vwxv"></div></div></footer></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href="/docs/projects/gotsrpc/service-interfaces"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">Service Interfaces</div></a><a class="pagination-nav__link pagination-nav__link--next" href="/docs/projects/gotsrpc/service-interfaces/errors"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Errors</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#scalar-types" class="table-of-contents__link toc-highlight">Scalar types</a><ul><li><a href="#supported-in-go-and-typescript" class="table-of-contents__link toc-highlight">Supported in Go and TypeScript</a></li><li><a href="#numerics--numbers" class="table-of-contents__link toc-highlight">Numerics / numbers</a></li><li><a href="#type-aliases" class="table-of-contents__link toc-highlight">Type Aliases</a></li></ul></li><li><a href="#enumerations" class="table-of-contents__link toc-highlight">Enumerations</a></li><li><a href="#slices" class="table-of-contents__link toc-highlight">Slices</a><ul><li><a href="#scalar-types-1" class="table-of-contents__link toc-highlight">Scalar types</a></li><li><a href="#other-slice-type-examples" class="table-of-contents__link toc-highlight">Other slice type examples</a><ul><li><a href="#structs" class="table-of-contents__link toc-highlight">Structs</a></li><li><a href="#nested-slices" class="table-of-contents__link toc-highlight">Nested slices</a></li></ul></li></ul></li><li><a href="#maps--records" class="table-of-contents__link toc-highlight">Maps / Records</a><ul><li><a href="#scalars" class="table-of-contents__link toc-highlight">Scalars</a></li><li><a href="#structs-1" class="table-of-contents__link toc-highlight">Structs</a></li><li><a href="#slices-1" class="table-of-contents__link toc-highlight">Slices</a></li></ul></li><li><a href="#map-types" class="table-of-contents__link toc-highlight">Map types</a></li><li><a href="#nested-map-types" class="table-of-contents__link toc-highlight">Nested map types</a></li><li><a href="#structs--interfaces" class="table-of-contents__link toc-highlight">Structs / Interfaces</a><ul><li><a href="#field-names" class="table-of-contents__link toc-highlight">Field names</a><ul><li><a href="#default-go--typescript" class="table-of-contents__link toc-highlight">Default Go => TypeScript</a></li><li><a href="#idiomatic-field-names" class="table-of-contents__link toc-highlight">Idiomatic field names</a></li></ul></li><li><a href="#optional-and-nullable-fields" class="table-of-contents__link toc-highlight">Optional and nullable fields</a></li><li><a href="#hiding-values-from-the-client" class="table-of-contents__link toc-highlight">Hiding values from the client</a></li><li><a href="#union-types" class="table-of-contents__link toc-highlight">Union Types</a><ul><li><a href="#scalars-1" class="table-of-contents__link toc-highlight">Scalars</a></li><li><a href="#structs-2" class="table-of-contents__link toc-highlight">Structs</a></li></ul></li></ul></li></ul></div></div></div></div></main></div></div></div><footer class="footer"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">github</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://github.com/foomo" target="_blank" rel="noopener noreferrer" class="footer__link-item">https://github.com/foomo</a></li></ul></div><div class="col footer__col"><div class="footer__title">legal</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/etc/imprint">Imprint</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">© 2024 bestbytes</div></div></div></footer></div>
|
|
</body>
|
|
</html> |