<!doctype html><metacharset=utf-8><metaname=viewportcontent="width=device-width,initial-scale=1"><linkrel=stylesheethref=https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown-dark.css><style>.markdown-body{box-sizing:border-box;min-width:200px;max-width:980px;margin:0auto;padding:45px}@media(max-width:767px){.markdown-body{padding:15px}}</style><bodyclass=markdown-body><ahref=index>Index</a><h1><aid=user-content-experiment-goclass=anchoraria-hidden=truehref=#experiment-go><spanaria-hidden=trueclass="octicon octicon-link"></span></a>Experiment Go</h1><p>There come a time when you need to experiment new things, new style, new approach.
So this post serves as it is named.<h1><aid=user-content-design-api-by-trimming-down-the-interfacestruct-or-whateverclass=anchoraria-hidden=truehref=#design-api-by-trimming-down-the-interfacestruct-or-whatever><spanaria-hidden=trueclass="octicon octicon-link"></span></a>Design API by trimming down the interface/struct or whatever</h1><p>Instead of:<divclass="highlight highlight-source-go"><pre><spanclass=pl-k>type</span><spanclass=pl-smi>Client</span><spanclass=pl-k>interface</span> {
<spanclass=pl-s1>c</span>.<spanclass=pl-c1>Account</span>.<spanclass=pl-en>Remove</span>()</pre></div><p>The difference is <code>c.GetUser()</code> -> <code>c.User.Get()</code>.<p>For example we have client which connect to bank.
There are many functions like <code>GetUser</code>, <code>GetTransaction</code>, <code>VerifyAccount</code>, ...
So split big client to many children, each child handle single aspect, like user or transaction.<p>My concert is we replace an interface with a struct which contains multiple interfaces aka children.
I don't know if this is the right call.<p>This pattern is used by <ahref=https://github.com/google/go-github>google/go-github</a>.<h2><aid=user-content-find-alternative-to-grpcgrpc-goclass=anchoraria-hidden=truehref=#find-alternative-to-grpcgrpc-go><spanaria-hidden=trueclass="octicon octicon-link"></span></a>Find alternative to <ahref=https://github.com/grpc/grpc-go>grpc/grpc-go</a></h2><p>Why?
<ahref="https://github.com/grpc/grpc-go/issues?q=is%3Aissue+compatibility+is%3Aclosed">See for yourself</a>.
Also read <ahref=https://go.dev/blog/protobuf-apiv2rel=nofollow>A new Go API for Protocol Buffers</a> to know why <code>v1.20.0</code> is <code>v2</code>.<p>Currently there are some:<ul><li><ahref=https://github.com/bufbuild/connect-go>bufbuild/connect-go</a>. Comming from buf, trust worthy but need time to make it match feature parity with grpc-go.<li><ahref=https://github.com/twitchtv/twirp>twitchtv/twirp</a><li><ahref=https://github.com/storj/drpc>storj/drpc</a></ul><h1><aid=user-content-thanksclass=anchoraria-hidden=truehref=#thanks><spanaria-hidden=trueclass="octicon octicon-link"></span></a>Thanks</h1><ul><li><ahref=https://blog.gopheracademy.com/advent-2019/api-clients-humans/rel=nofollow>API Clients for Humans</a></ul><ahref=mailto:hauvipapro+posts@gmail.com>Feel free to ask me via email</a>