View handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (api ProductsAPI) Create() http.HandlerFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
var product models.Product | |
if r.Method != http.MethodPost { | |
code := http.StatusMethodNotAllowed | |
httpError := common.NewError(common.HTTPFriendlyStatus(code), code) | |
common.SendErrorResult(w, httpError) | |
return | |
} |
View exampe_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestHandler(t *testing.T) { | |
testcases := []struct { | |
name string | |
request *http.Request | |
code int | |
}{ | |
{ | |
name: "Wrong-Method", | |
request: NewRequest(t, http.MethodGet, "/", nil), | |
code: 405, |
View sse.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// v2 of the great example of SSE in go by @ismasan. | |
// includes fixes: | |
// * infinite loop ending in panic | |
// * closing a client twice | |
// * potentially blocked listen() from closing a connection during multiplex step. | |
package main | |
import ( | |
"fmt" | |
"log" |
View Install protobuf 3.6.1 on Ubuntu 16.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Make sure you grab the latest version | |
curl -OL https://github.com/google/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip | |
https://github.com/google/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip | |
# Unzip | |
unzip protoc-3.6.1-linux-x86_64.zip -d protoc3 | |
# Move protoc to /usr/local/bin/ | |
sudo mv protoc3/bin/* /usr/local/bin/ |