[Golang] Build A Simple Web Service part.1 — HTTP/net & multiplexer

Jen-Hsuan Hsieh (Sean)
A Layman
Published in
15 min readDec 29, 2018

--

Copy right@A Layman

Introduction

使用Go搭建產品的核心或是一部分的Component的團隊越來越多,就開始對這個語言感到好奇開始學習,故寫下學習的過程作為記錄。

結合工作上的side project,構想是用Go開發web service並提供單純的API供前端頁面使用,頁面會用React.js開發,而這一系列的文章會先著重在Golang WebDev上。

Go的web framework很多,MVC如Iris, Beego都是一時之選,使用原生的HTTP/net package也足以提供搭建web service所需要的功能,不足之處可搭配web tool kit如Gorilla,需求來決定,並不一定要使用到MVC框架。這篇文章則會從原生的HTTP/net為主。

I was curious about Golang and started to study it with the number of teams which develop their products or core components by using this language increasing. I decided to write down these articles during my learning journey.

The series of these articles focus on WebDev. I will use Golang to develop web services which were responsible for providing API to the React pages in my side project.

There are many choices for Golang frameworks such as MVC framework like Iris, Beego. However, I will use the native HTTP/net package and web tool kit (Gorilla) in this article. I thought it was enough for my needs.

Interface & HTTP/net

Go的interface是一種類別,以type關鍵字宣告。欲實作interface只要實作它所定義的函式即可。

--

--

Jen-Hsuan Hsieh (Sean)
A Layman

Frontend Developer🚀 Angular • React • Nest • Electron • Micro-frontend • Monorepo Architecture • https://daily-learning.herokuapp.com/