Clone this repo:
  1. 47ae307 Merge pull request #10 from lann/registry-mux by Lann · 6 years ago master
  2. 577d1d0 Update .travis.yml by Lann · 6 years ago registry-mux
  3. ce88ec4 Wrap registry map access in RWMutex by Lann · 6 years ago
  4. 1b87b36 Create LICENSE by Lann · 6 years ago
  5. f22ce00 Merge pull request #6 from lann/fix-ps by Lann · 9 years ago

Builder - fluent immutable builders for Go

GoDoc Build Status

Builder was originally written for Squirrel, a fluent SQL generator. It is probably the best example of Builder in action.

Builder helps you write fluent DSLs for your libraries with method chaining:

resp := ReqBuilder.
    Header("User-Agent", "Builder").

Builder uses immutable persistent data structures (these, specifically) so that each step in your method chain can be reused:

build := WordBuilder.AddLetters("Build")
builder := build.AddLetters("er")
building := build.AddLetters("ing")

Builder makes it easy to build structs using the builder pattern (surprise!):

import ""

type Muppet struct {
    Name string
    Friends []string

type muppetBuilder builder.Builder

func (b muppetBuilder) Name(name string) muppetBuilder {
    return builder.Set(b, "Name", name).(muppetBuilder)

func (b muppetBuilder) AddFriend(friend string) muppetBuilder {
    return builder.Append(b, "Friends", friend).(muppetBuilder)

func (b muppetBuilder) Build() Muppet {
    return builder.GetStruct(b).(Muppet)

var MuppetBuilder = builder.Register(muppetBuilder{}, Muppet{}).(muppetBuilder)
    AddFriend("Dr. Honeydew").

=> Muppet{Name:"Beaker", Friends:[]string{"Dr. Honeydew"}}


Builder is released under the MIT License.