About Pretty Printing

JSON cat xxx.json | jq . XML cat xxx.xml | xmllint --format -

February 1, 2016

Sending Email from Gmail using Go

Turn on “2-Step Verification” so that an “App password” can be generated go get gopkg.in/gomail.v2 Send your Email like the example below: package main import ( "gopkg.in/gomail.v2" ) func main() { m := gomail.NewMessage() m.SetHeader("From", "[email protected]") m.SetAddressHeader("To", "to_adress@xxx", "to_name") m.SetAddressHeader("Cc", "cc_adress@xxx", "cc_name") m.SetHeader("Subject", "Hello! TEST!") m.SetBody("text/html", "Hello! <b>TEST</b>!") d := gomail.NewPlainDialer("smtp.gmail.com", 587, "[email protected]", "the App password") if err := d.DialAndSend(m); err != nil { panic(err) } }

January 31, 2016

SSH Resources in Go

golang.org/x/crypto/ssh github.com/YuriyNasretdinov/GoSSHa Articles: SSH Client connection in Golang Using Go to Execute Commands on Hundreds of Servers with SSH

January 31, 2016

SEJ: Message Queue Based on Segmented Journals

h12.io/sej provides composable components of distributed, persisted message queue and allows trading off between reliablilty, latency and throughput with minimal devops overhead. Package Organization h12.io/sej: writer, scanner and offset shard: sharding hub: copying across machines cmd/sej: command line tool SEJ Directory [root-dir]/ [sej-dir]/ jnl.lck jnl/ 0000000000000000.jnl 000000001f9e521e.jnl ...... ofs/ reader1.ofs reader1.lck reader2.ofs reader2.lck ...... Journal File format segment_file = { message } . message = offset timestamp type key value size . offset = uint64 . timestamp = int64 . type = uint8 . key = key_size { uint8 } . key_size = int8 . value = value_size { uint8 } . value_size = int32 . size = int32 . All integers are written in the big endian format. ...

November 14, 2015

RealTest: real test environment for Go

h12.io/realtest provides real test environment for Go unit testing, based on Docker. Includes: Queue Kafka cluster (with zookeeper) Database: MySQL MongoDB Cache Redis Configuration service ZooKeeper

November 14, 2015

JSON Schema parser & code generator

json-schema generates Go struct from a JSON Schema specification. Decimal types are supported for accurate currency calculation.

November 4, 2015

Aliyun OSS Go SDK

Aliyun OSS (Object Storage Service) Go SDK is a client SDK to access Aliyun OSS API, implemented in the Go programming language. Installation go get -u github.com/aliyun/aliyun-oss-go-sdk/oss go test -v -cover github.com/aliyun/aliyun-oss-go-sdk/oss Highlights Complete set of Aliyun OSS API Thouroughly tested 100% test coverage intuitive table driven tests full test suite completes within 2 seconds Lint clean golint go fmt goimports go vet race detector Idiomatic & elegant response is returned as a parsed object error is returned as a Go error named options for setting headers & parameters Great extensibility clean and orthogonal implementation users can easily extend the SDK when a new API method is supported No third party dependencies Documentation Overview API Object Bucket Object Optional Headers and Parameters Multipart Upload Cross-Origin Resource Sharing (CORS) Object Lifecycle Management Extending the SDK Differences with Python SDK HTTP header User-Agent, e.g. aliyun-sdk-go/0.1.1 (Linux/3.16.0-51-generic/x86_64;go1.5.1) Go HTTP client does not support 100-Continue (will be supported after Go 1.6, see https://github.com/golang/go/issues/3665) HTTP header keys are automatically converted into canonical format, e.g. x-oss-acl becomes X-Oss-Acl Go GET request does not have redundant “Content-Length: 0” header Parameters will be omitted if the argument is not set Go always sends URL parameters and headers in canonical order License licensed under the Apache License 2.0 ...

October 22, 2015

How to Remove All Exited Containers & Dangling Images for Docker?

Updates at 2020-07-08: docker system prune Old tricks: docker ps --quiet --filter=status=exited | xargs docker rm docker images --no-trunc=true --filter="dangling=true" --quiet=true | xargs docker rmi

August 3, 2015

kpax: a modular & idiomatic Kafka client in Go

Install go get -u h12.io/kpax Talk I gave a talk about Kpax at Gopher Meetup Shanghai 2016. See the slides. Design The client is built on top of Kafka Wire Protocol (i.e. low-level API). The protocol related types & marshal/unmarshal functions are automatically generated by wipro from the HTML spec). (-) means to be done. Sub packages model is an abstraction model for request, response, broker and cluster broker is a lazy, asynchronous and recoverable round tripper that talks to a single Kafka broker cluster is a metadata manager that talks to a Kafka cluster proto contains both low level API and a “middle” level facade producer: fault tolerant high-level producer (batching and partitioning strategy) consumer: fault tolerant high-level consumer (consumer group and offset commit) log: replaceable global logger cmd kpax: command line tool to help with Kafka programming Compatibility Compatible with Kafka Server 0.8.2. ...

July 23, 2015

A Comprehensive Note about Proxy Settings

Git > cat ~/.gitconfig [http] proxy = socks5://[host]:[port] [https] proxy = socks5://[host]:[port] Curl (Homebrew) > cat ~/.curlrc socks5 = "[host]:[port]" Docker pull env HTTP_PROXY=http://xxx docker pull yyy GAE Set proxy export HTTP_PROXY http://[host]:[port] export HTTPS_PROXY http://[host]:[port] Delete cacerts.txt under GAE SDK installation to disable SSL verification ( make sure the proxy is safe before this step). Deploy. appcfg.py . --email=[address] --passin

July 8, 2015