foomo-docs/assets/js/06e8b2de.bb445db0.js
2023-04-21 21:01:59 +00:00

1 line
8.5 KiB
JavaScript

"use strict";(self.webpackChunkfoomo=self.webpackChunkfoomo||[]).push([[7478],{3905:(e,t,n)=>{n.d(t,{Zo:()=>s,kt:()=>g});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},l=Object.keys(e);for(r=0;r<l.length;r++)n=l[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r<l.length;r++)n=l[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var i=r.createContext({}),c=function(e){var t=r.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},s=function(e){var t=c(e.components);return r.createElement(i.Provider,{value:t},e.children)},d="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,l=e.originalType,i=e.parentName,s=p(e,["components","mdxType","originalType","parentName"]),d=c(n),m=a,g=d["".concat(i,".").concat(m)]||d[m]||u[m]||l;return n?r.createElement(g,o(o({ref:t},s),{},{components:n})):r.createElement(g,o({ref:t},s))}));function g(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var l=n.length,o=new Array(l);o[0]=m;var p={};for(var i in t)hasOwnProperty.call(t,i)&&(p[i]=t[i]);p.originalType=e,p[d]="string"==typeof e?e:a,o[1]=p;for(var c=2;c<l;c++)o[c]=n[c];return r.createElement.apply(null,o)}return r.createElement.apply(null,n)}m.displayName="MDXCreateElement"},6315:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>i,contentTitle:()=>o,default:()=>u,frontMatter:()=>l,metadata:()=>p,toc:()=>c});var r=n(7462),a=(n(7294),n(3905));const l={},o="Playground",p={unversionedId:"projects/gotsrpc/playground/index",id:"projects/gotsrpc/playground/index",title:"Playground",description:"The gotsrpc playground is designed to:",source:"@site/docs/projects/gotsrpc/playground/index.md",sourceDirName:"projects/gotsrpc/playground",slug:"/projects/gotsrpc/playground/",permalink:"/docs/projects/gotsrpc/playground/",draft:!1,editUrl:"https://github.com/foomo/foomo-docs/tree/main/foomo/docs/projects/gotsrpc/playground/index.md",tags:[],version:"current",frontMatter:{},sidebar:"projectsSidebar",previous:{title:"TypeScript client transport",permalink:"/docs/projects/gotsrpc/client-transport"},next:{title:"Hello, World!",permalink:"/docs/projects/gotsrpc/playground/hello-world"}},i={},c=[{value:"Installing and running the playground",id:"installing-and-running-the-playground",level:2},{value:"Project layout",id:"project-layout",level:2}],s={toc:c},d="wrapper";function u(e){let{components:t,...n}=e;return(0,a.kt)(d,(0,r.Z)({},s,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"playground"},"Playground"),(0,a.kt)("p",null,"The gotsrpc playground is designed to:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"provide examples for this documentation"),(0,a.kt)("li",{parentName:"ul"},"make it easy to play with gotsrpc on your local machine")),(0,a.kt)("p",null,"It is ",(0,a.kt)("strong",{parentName:"p"},"NOT")," an example project to build an actual production service, because:"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"it has a purely educational layout"),(0,a.kt)("li",{parentName:"ul"},"all services are exposed from one go program"),(0,a.kt)("li",{parentName:"ul"},"all service implementations are naive demo code with focus on documentation"),(0,a.kt)("li",{parentName:"ul"},"all service implementations are in one package")),(0,a.kt)("h2",{id:"installing-and-running-the-playground"},"Installing and running the playground"),(0,a.kt)("p",null,"Prerequisites"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},"Go"),(0,a.kt)("li",{parentName:"ul"},"Node.js")),(0,a.kt)("p",null,"Clone repo"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-shell"},"git clone git@github.com:foomo/gotsrpc-playground.git ~/go/src/github.com/foomo/gotsrpc-playground\n")),(0,a.kt)("p",null,"Run playground"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-shell"},"cd ~/go/src/github.com/foomo/gotsrpc-playground\nmake run\n")),(0,a.kt)("p",null,"Open the playground ",(0,a.kt)("a",{parentName:"p",href:"http://127.0.0.1:8080"},"http://127.0.0.1:8080")),(0,a.kt)("h2",{id:"project-layout"},"Project layout"),(0,a.kt)("p",null,"Note : this is not a recommendation for a general project layout - it is purely educational."),(0,a.kt)("table",null,(0,a.kt)("thead",{parentName:"table"},(0,a.kt)("tr",{parentName:"thead"},(0,a.kt)("th",{parentName:"tr",align:null},"Location"),(0,a.kt)("th",{parentName:"tr",align:null},"Description"))),(0,a.kt)("tbody",{parentName:"table"},(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"server")),(0,a.kt)("td",{parentName:"tr",align:null},"server go code")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"server/services")),(0,a.kt)("td",{parentName:"tr",align:null},"service interfaces, one service interface per package helloworld, todos, ...")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"server/server")),(0,a.kt)("td",{parentName:"tr",align:null},"One package to implement all service interfaces with one file per service package - in a real world scenario, that typically is one package per service interface")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"server/main.go")),(0,a.kt)("td",{parentName:"tr",align:null},"Go program, that exposes all service implementations and reverse proxies the Next.js frontend which is running on ",(0,a.kt)("a",{parentName:"td",href:"http://127.0.0.1:3000"},"http://127.0.0.1:3000"))),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"client")),(0,a.kt)("td",{parentName:"tr",align:null},"Next.js TypeScript client created with ",(0,a.kt)("inlineCode",{parentName:"td"},"npx create-next-app@latest --typescript"))),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("a",{parentName:"td",href:"https://github.com/foomo/gotsrpc-playground/blob/main/client/services/transport.ts"},(0,a.kt)("inlineCode",{parentName:"a"},"client/services/transport.ts"))),(0,a.kt)("td",{parentName:"tr",align:null},"An example transport implemenation")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"client/services/generated")),(0,a.kt)("td",{parentName:"tr",align:null},"Target for generated TypeScript clients and value objects as defined in ",(0,a.kt)("inlineCode",{parentName:"td"},"gotsrpc.yaml"))))),(0,a.kt)("p",null,"ie relevant files per example:"),(0,a.kt)("table",null,(0,a.kt)("thead",{parentName:"table"},(0,a.kt)("tr",{parentName:"thead"},(0,a.kt)("th",{parentName:"tr",align:null},"File"),(0,a.kt)("th",{parentName:"tr",align:null},"Description"))),(0,a.kt)("tbody",{parentName:"table"},(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"server/services/<example>/service.go")),(0,a.kt)("td",{parentName:"tr",align:null},"service interface definition")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"server/server/<example>.go")),(0,a.kt)("td",{parentName:"tr",align:null},"service implementation")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"client/pages/<example>.tsx")),(0,a.kt)("td",{parentName:"tr",align:null},"Next.js example page")),(0,a.kt)("tr",{parentName:"tbody"},(0,a.kt)("td",{parentName:"tr",align:null},(0,a.kt)("inlineCode",{parentName:"td"},"client/styles/<Example>.module.css")),(0,a.kt)("td",{parentName:"tr",align:null},"CSS")))))}u.isMDXComponent=!0}}]);