Pitfall of Go HTTP Header Operation

Use example to explain common mistakes when operating HTTP Header in Go

ta-ching chen

4 minute read


Most of the recent works are working on manipulating HTTP header in Go and noticed some common mistakes people may fall into while in development. So following we will go through some examples to see how to prevent and resolve these problems.

All sample code can be found at Github Repo

ResponseWriter.Write causes client receives wrong HTTP status code

First, let’s see the following function and guess what HTTP status code user will receive.

http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {

400 Bad Request? No, the answer is 200 OK。

$ curl -i
HTTP/1.1 200 OK
Date: Thu, 20 Dec 2018 06:31:33 GMT
Content-Length: 6
Content-Type: text/plain; charset=utf-8

ta-ching chen

4 minute read


At Part 2, we knew what’s real payload was passed to function and how to create a serverless guesbook. In the last post, we will go through the final bank sample and know how to deploy a application to different fission clusters.

A Serverless Bank Application in Golang (Sample)

In this section, we use a more complex bank sample to demonstrate how to use AJAX interacts with fission functions.

Fission Bank Diagram

ta-ching chen

6 minute read


Part 1 we talked about the advantage of adopting fission as serverless framework on kubernetes, basic concept of around fission core and how to create a simple HelloWorld example with fission.

In this post we’ll dive deeper to see what’s the payload of a HTTP request being passed to user function and learn how to create a guestbook application consists with REST functions in Golang.

How Fission maps HTTP requests to user function

Before we diving into code, we first need to understand what exactly happened inside Fission. Here is a brief diagram describes how requests being sent to function inside Kubernetes cluster.

router maps req to fn

The requests will first come to the router and it checks whether the destination URL and HTTP method are registered by http trigger. Once both are matched, router will then proxy request to the function pod (a pod specialized with function pointed by http trigger) to get response from it; reject, otherwise.

ta-ching chen

8 minute read


When users try to develop serverless applications, they often choose to start with serverless services offered on public clouds, like AWS Lambda or Google Cloud Functions. However, users may encounter following problems after application development:

  1. Simulating the same environment on local machines is difficult
  2. Vendor lock-in prevents moving applications from one cloud provider to another
  3. Sensitive data that should not be sent outside an on-premises datacenter

Fission is a serverless framework built on top of Kubernetes. Here are some benefits for adopting Fission as serverless solution to develop a severless application:

  • Portability
    • Laptop, PC, On-premises datacenter, even cloud providers. Wherever you can run Kubernetes, you can run Fission.
    • Recreate a serverless application in short time with fission spec files.
  • Support rich event sources
    • HTTP Trigger
    • Message queue trigger: NATS, Kafka
    • Time trigger
  • Rich Environment (Language) supportability
    • NodeJs, Go, Python, Java (JVM languages), Ruby, Perl, PHP7, DotNet, DotNet2, Binary
    • BYOE (Build Your Own Environment)
  • Build automation
    • Builder manager inside Fission helps to create a deployable function package from source code.

After seeing these advantages for adopting Fission as serverless framework, you may feel exciting and start wondering how to create a serverless applciation with Fission. Let’s dive into the concepts of fission first.