예제 #1
0
}

func (b simpleExprBuilder) Add(i int) simpleExprBuilder {
	return builder.Append(b, "Adds", i).(simpleExprBuilder)
}

func (b simpleExprBuilder) Subtract(i int) simpleExprBuilder {
	return builder.Append(b, "Subtracts", i).(simpleExprBuilder)
}

func (b simpleExprBuilder) Equals() int {
	return builder.GetStruct(b).(simpleExpr).Equals()
}

// SimpleExprBuilder is an empty builder
var SimpleExprBuilder = builder.Register(simpleExprBuilder{}, simpleExpr{}).(simpleExprBuilder)

// End builder definition

func Example_basic() {
	b := SimpleExprBuilder.Add(10).Subtract(3)

	// Intermediate values can be reused
	b2 := b.Multiplier(2)
	b3 := b.Multiplier(3)

	fmt.Println(b.Equals(), b2.Equals(), b3.Equals())

	// Output:
	// 7 14 21
}
예제 #2
0
func init() {
	builder.Register(InsertBuilder{}, insertData{})
}
예제 #3
0
func (b searchReqBuilder) Accepted(flag bool) searchReqBuilder {
	return builder.Set(b, "Accepted", flag).(searchReqBuilder)
}

func (b searchReqBuilder) Tags(tags []string) searchReqBuilder {
	return builder.Set(b, "Tags", tags).(searchReqBuilder)
}

func (b searchReqBuilder) Build() SearchRequest {
	return builder.GetStruct(b).(SearchRequest)
}

// Answer Request Builder
type answersReqBuilder builder.Builder

func (b answersReqBuilder) AddAnswerID(v int) answersReqBuilder {
	return builder.Append(b, "AnswerIDS", v).(answersReqBuilder)
}

func (b answersReqBuilder) SiteID(v string) answersReqBuilder {
	return builder.Set(b, "SiteID", v).(answersReqBuilder)
}

func (b answersReqBuilder) Build() AnswerRequest {
	return builder.GetStruct(b).(AnswerRequest)
}

// Register Builders
var SearchRequestBuilder = builder.Register(searchReqBuilder{}, SearchRequest{}).(searchReqBuilder)
var AnswerRequestBuilder = builder.Register(answersReqBuilder{}, AnswerRequest{}).(answersReqBuilder)
예제 #4
0
func init() {
	builder.Register(FunctionBuilder{}, functionData{})
}
예제 #5
0
	return builder.Set(b, "X", i).(fooBuilder)
}

func (b fooBuilder) Y(i int) fooBuilder {
	return builder.Set(b, "Y", i).(fooBuilder)
}

func (b fooBuilder) I(i interface{}) fooBuilder {
	return builder.Set(b, "I", i).(fooBuilder)
}

func (b fooBuilder) Add(i int) fooBuilder {
	return builder.Append(b, "Add", i).(fooBuilder)
}

var FooBuilder = builder.Register(fooBuilder{}, Foo{}).(fooBuilder)

type unregBuilder builder.Builder

func (b unregBuilder) Add(i int) unregBuilder {
	return builder.Append(b, "X", i).(unregBuilder)
}

func assertInt(t *testing.T, b fooBuilder, key string, val int) {
	v, ok := builder.Get(b, key)
	if !ok {
		t.Errorf("key %v not set", key)
		return
	}
	i := v.(int)
	if i != val {
예제 #6
0
func init() {
	builder.Register(UpdateBuilder{}, updateData{})
}
예제 #7
0
func init() {
	builder.Register(DeleteBuilder{}, deleteData{})
}
예제 #8
0
func init() {
	builder.Register(ContainerBuilder{}, containerData{})
}
예제 #9
0
func init() {
	builder.Register(SelectBuilder{}, selectData{})
}
예제 #10
0
파일: copy.go 프로젝트: denkhaus/beamer
package tasks

import (
	"github.com/lann/builder"
	"gopkg.in/pipe.v2"
)

type copyCtx struct {
	Source string
	Dest   string
}

var Copy = builder.Register(copyBuilder{}, copyCtx{}).(copyBuilder)

type copyBuilder builder.Builder

//############################################################################
func (b copyBuilder) From(src string) copyBuilder {
	return builder.Set(b, "Source", src).(copyBuilder)
}

//############################################################################
func (b copyBuilder) To(dest string) copyBuilder {
	return builder.Set(b, "Dest", dest).(copyBuilder)
}

//############################################################################
func (b copyBuilder) Descr(descr string) copyBuilder {
	return builder.Set(b, "Description", descr).(copyBuilder)
}
예제 #11
0
	return builder.GetStructLike(b, Message{}).(Message)
}

func (b jsonBuilder) BuildReply() Reply {
	return builder.GetStructLike(b, Reply{}).(Reply)
}

func (b jsonBuilder) BuildCase() Case {
	return builder.GetStructLike(b, Case{}).(Case)
}

func (b jsonBuilder) BuildDraft() Draft {
	return builder.GetStructLike(b, Draft{}).(Draft)
}

func (b jsonBuilder) BuildNote() Note {
	return builder.GetStructLike(b, Note{}).(Note)
}

func (b jsonBuilder) BuildCompany() Company {
	return builder.GetStructLike(b, Company{}).(Company)
}

var CaseBuilder = builder.Register(jsonBuilder{}, Case{}).(jsonBuilder)
var MessageBuilder = builder.Register(jsonBuilder{}, Message{}).(jsonBuilder)
var ReplyBuilder = builder.Register(jsonBuilder{}, Reply{}).(jsonBuilder)
var CustomerBuilder = builder.Register(jsonBuilder{}, Customer{}).(jsonBuilder)
var DraftBuilder = builder.Register(jsonBuilder{}, Draft{}).(jsonBuilder)
var NoteBuilder = builder.Register(jsonBuilder{}, Note{}).(jsonBuilder)
var CompanyBuilder = builder.Register(jsonBuilder{}, Company{}).(jsonBuilder)
예제 #12
0
파일: mkdir.go 프로젝트: denkhaus/beamer
//############################################################################
func Mkdir(directory string) dirBuilder {
	dir := builder.Register(dirBuilder{}, dirCtx{}).(dirBuilder)
	return builder.Set(dir, "Directory", directory).(dirBuilder)
}
예제 #13
0
	ptr := &t
	rb = builder.Set(rb, "After", ptr).(ruleBuilder)
	rb = rb.updateTypeAccordingTo(ptr)
	return rb
}
func (rb ruleBuilder) Before(t time.Time) ruleBuilder {
	ptr := &t
	rb = builder.Set(rb, "Before", ptr).(ruleBuilder)
	rb = rb.updateTypeAccordingTo(ptr)
	return rb
}

// callback
func (rb ruleBuilder) Custom(cb CustomCallback) ruleBuilder {
	return builder.Append(rb, "Customs", cb).(ruleBuilder)
}
func (rb ruleBuilder) Alter(cb AlterCallback) ruleBuilder {
	return builder.Append(rb, "Alters", cb).(ruleBuilder)
}
func (rb ruleBuilder) Prepare(cb PrepareCallback) ruleBuilder {
	return builder.Append(rb, "Prepares", cb).(ruleBuilder)
}

// custom
func (rb ruleBuilder) Email() ruleBuilder {
	return builder.Set(rb, "Regex", `(?i)[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}`).(ruleBuilder)
}

var RuleBuilder = builder.Register(ruleBuilder{}, Rule{}).(ruleBuilder)
var RB = RuleBuilder
예제 #14
0
파일: beamer.go 프로젝트: denkhaus/beamer
package main

import (
	"github.com/denkhaus/beamer/common"
	"github.com/denkhaus/tcgl/applog"
	"github.com/lann/builder"
	"gopkg.in/pipe.v2"
)

type assembleFunc func() (pipe.Pipe, error)

var Beamer = builder.Register(beamerBuilder{}, common.BeamerCtx{}).(beamerBuilder)

type beamerBuilder builder.Builder

//############################################################################
func (p beamerBuilder) Sequence(ctxs ...common.TaskCtx) beamerBuilder {
	b := p
	for _, c := range ctxs {
		b = builder.Append(b, "Tasks", c).(beamerBuilder)
	}

	return b
}

//############################################################################
func (p beamerBuilder) Set(key string, value interface{}) beamerBuilder {
	m, ok := builder.Get(p, "KVStore")

	if ok {
		store := m.(map[string]interface{})
예제 #15
0
func init() {
	builder.Register(CaseBuilder{}, caseData{})
}