Releasing Gocial

Releasing Gocial

ยท

3 min read

More than a year ago I started working on a side project born out of the furstration I had with buffer, ifttt and zapier. The use case was pretty simple: I just wanted to share an article and some comments about it on multiple social media platforms from a single location.

All sharing services had great functionalities (e.g. automated workflows[^fn:1]) but you're always limited in the number of shares you can distribute withing a time frame without paying for premium. At the same time they all lacked support for LinkedIn which then sparked the idea for gocial. After having a look at the LinkedIn Post API[^fn:2]

I decided I'll implement my own service in Golang and learn more about OAuth and JWT tokens.

img

Design

For the overall system design I use a serverless environment to run my Golang binary. Currently I use netlify.com to host my Lambda function which serves all the functionalities via HTTP and some REST API.

As for the software architecture I've used hexagonal architecture to have more or less strict boundaries between the domains and enable lose coupling.

Sketching ideas

As always I've started with a rough idea how the code structure should like. Initially I wrote down some ideas on my whiteboard and codified these later on.

img

Hexagonal Architecture

I know the picture below doesn't look like an hexagonal structure but it should at least emphasize what the core domain is about.

๐Ÿ‘‰ I've recently release an online presentation on this topic. Checkout Hexagonal Architecture (Basic Introduction using Python). img

Project layout

For the project structure/layout I've decided to go with this structure:

gocial:

โ”œโ”€โ”€ cli
โ”œโ”€โ”€ docs
โ”œโ”€โ”€ internal
โ”œโ”€โ”€ lambda
โ””โ”€โ”€ server
Code Snippet 1: Overall project structure

/internal

This is where the gocial specific domain code goes to. This includes entities, different services and the authentication part.

./internal
โ”œโ”€โ”€ config
โ”‚   โ””โ”€โ”€ config.go
โ”œโ”€โ”€ entity
โ”‚   โ”œโ”€โ”€ identity.go
โ”‚   โ”œโ”€โ”€ providers.go
โ”‚   โ””โ”€โ”€ share.go
โ”œโ”€โ”€ identity
โ”‚   โ”œโ”€โ”€ cookie_repository.go
โ”‚   โ”œโ”€โ”€ file_repository.go
โ”‚   โ””โ”€โ”€ repository.go
โ”œโ”€โ”€ jwt
โ”‚   โ””โ”€โ”€ token.go
โ”œโ”€โ”€ oauth
โ”‚   โ”œโ”€โ”€ goth_repository.go
โ”‚   โ”œโ”€โ”€ repository.go
โ”‚   โ””โ”€โ”€ service.go
โ””โ”€โ”€ share
โ”œโ”€โ”€ linkedin_repository.go
โ”œโ”€โ”€ repository.go
โ”œโ”€โ”€ service.go
โ””โ”€โ”€ twitter_repository.go

/server

./server
โ”œโ”€โ”€ api.go
โ”œโ”€โ”€ html
โ”‚   โ”œโ”€โ”€ html.go
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ package-lock.json
โ”‚   โ”œโ”€โ”€ postcss.config.js
โ”‚   โ”œโ”€โ”€ static
โ”‚   โ”‚   โ””โ”€โ”€ main.css
โ”‚   โ”œโ”€โ”€ tailwind.config.js
โ”‚   โ”œโ”€โ”€ tailwind.css
โ”‚   โ”œโ”€โ”€ tailwind.js
โ”‚   โ””โ”€โ”€ templates
โ”‚       โ”œโ”€โ”€ about.html
โ”‚       โ”œโ”€โ”€ auth
โ”‚       โ”œโ”€โ”€ base.html
โ”‚       โ”œโ”€โ”€ index.html
โ”‚       โ”œโ”€โ”€ partials
โ”‚       โ””โ”€โ”€ share
โ”œโ”€โ”€ http.go
โ”œโ”€โ”€ oauth.go
โ””โ”€โ”€ share.go

This folder contains HTTP server specific functionalities:

  • /html
    • here I put all the HTML templates and components (partials)
    • I use tailwindCSS so there is a little bit of npm foo
  • http.go
    • responsible for launching the HTTP server and setting up API routes
    • renders HTML templates
  • api.go
    • handles different API routes (e.g. sharing articles/comments)
  • oauth.go
    • defines API endpoints for doing OAuth

Project repository

Check out the project repository ๐Ÿ‘‡

Check out the github repository

[^fn:1]: Initially I played with RSS and hugo for publishing content via a RSS feed which will then trigger posts on Twitter, LinkedIn & co. [^fn:2]: Which apparently now it's legacy and got replaced by the posts API.

ย