Esempio n. 1
2
func DumpDiff(expectedObj, actualObj interface{}) {
	expected := pretty.Sprintf("%# v\n", expectedObj)
	actual := pretty.Sprintf("%# v\n", actualObj)
	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(expected),
		B:        difflib.SplitLines(actual),
		FromFile: "expected",
		ToFile:   "actual",
		Context:  3,
	}
	text, _ := difflib.GetUnifiedDiffString(diff)
	fmt.Print(text)
}
Esempio n. 2
1
// format an error using pretty printing.
func format(userArgs interface{}, format string, internalArgs ...interface{}) (result string) {
	if len(userArgs.([](interface{}))) == 0 {
		result = fmt.Sprintf(format+"\n", internalArgs...)
	} else {
		internal := fmt.Sprintf(format, internalArgs...)
		result = fmt.Sprintf("\t%v\n%v\n", fmt.Formatter(userArgs), internal)
	}

	return
}
Esempio n. 3
1
// New makes a new Compose object
func New(config *Config) (*Compose, error) {
	compose := &Compose{
		Manifest: config.Manifest,
		DryRun:   config.DryRun,
		Attach:   config.Attach,
		Pull:     config.Pull,
		Wait:     config.Wait,
		Remove:   config.Remove,
	}

	cliConf := &DockerClient{
		Docker:     config.Docker,
		Attach:     config.Attach,
		Wait:       config.Wait,
		Auth:       config.Auth,
		KeepImages: config.KeepImages,
		Recover:    config.Recover,
	}

	cli, err := NewClient(cliConf)
	if err != nil {
		return nil, fmt.Errorf("Compose client initialization failed with error '%s' and config:\n%s", err,
			pretty.Sprintf("%# v", cliConf))
	}

	compose.client = cli

	return compose, nil
}
Esempio n. 4
1
func (cfg Config) String() string {
	m := make(map[string]interface{})
	err := cfg.Unmarshal(&m)
	if err != nil {
		panic(err)
	}
	return pretty.Sprintf("Config{%# v}", m)
}
Esempio n. 5
1
func handler(w http.ResponseWriter, r *http.Request) {
	rs := pretty.Sprintf("%# v\n", r)
	ws := pretty.Sprintf("%# v\n", w)

	if *verbose {
		log.Println(rs)
		log.Println(ws)
	}

	data := map[string]interface{}{
		"now":     time.Now(),
		"request": rs,
		"title":   "net/http debug server",
		"writer":  ws,
	}

	err := t.Execute(w, data)
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 6
1
func (sc *ServerCodec) ReadRequestBody(v interface{}) (err error) {
	log.Println(log.TRACE, "RPC Server Entered: ReadRequestBody")
	defer log.Println(log.TRACE, "RPC Server Leaving: ReadRequestBody")

	err = sc.Decoder.Decode(v)
	if err != nil {
		log.Println(log.ERROR, "RPC Server Error decoding request body: ", err)
	}

	if err == nil {
		log.Println(log.TRACE, pretty.Sprintf("RPC Server Read RequestBody %s %+v", reflect.TypeOf(v), v))
	}
	return
}
Esempio n. 7
1
func TestRequestWrite(t *testing.T) {
	for i, tt := range reqWriteTests {
		switch b := tt.Body.(type) {
		case []byte:
			tt.Req.Body = ioutil.NopCloser(bytes.NewBuffer(b))
		case func() io.ReadCloser:
			tt.Req.Body = b()
		}
		g, gflag, err := RequestFramingHeader(&tt.Req)
		w := tt.WantHeader
		if w != nil && !reflect.DeepEqual(g, w) {
			t.Errorf("#%d", i)
			t.Log(pretty.Sprintf("g = %# v", g))
			t.Log(pretty.Sprintf("w = %# v", w))
		}
		if tt.WantFlag != gflag {
			t.Errorf("#%d: flag = %v want %v", i, gflag, tt.WantFlag)
		}
		if g, w := fmt.Sprintf("%v", err), fmt.Sprintf("%v", tt.WantError); g != w {
			t.Errorf("#%d: err = %v want %v", i, g, w)
			continue
		}
	}
}
Esempio n. 8
1
func (cc *ClientCodec) WriteRequest(req *rpc.Request, v interface{}) (err error) {
	log.Println(log.TRACE, "RPC Client Entered: WriteRequest")
	defer log.Println(log.TRACE, "RPC Client Leaving: WriteRequest")

	log.Println(log.TRACE, pretty.Sprintf("RPC Client Writing RequestHeader %s %+v", reflect.TypeOf(req), req))

	err = cc.Encoder.Encode(req)
	if err != nil {
		log.Println(log.ERROR, "RPC Client Error enconding request rpc request: ", err)
		cc.Close()
		return
	}

	log.Println(log.TRACE, pretty.Sprintf("RPC Client Writing Request Value %s %+v", reflect.TypeOf(v), v))

	err = cc.Encoder.Encode(v)
	if err != nil {
		log.Println(log.ERROR, "RPC Client Error enconding request value: ", err)
		cc.Close()
		return
	}

	return
}
Esempio n. 9
1
func (sc *ServerCodec) WriteResponse(rs *rpc.Response, v interface{}) (err error) {
	log.Println(log.TRACE, "RPC Server Entered: WriteResponse")
	defer log.Println(log.TRACE, "RPC Server Leaving: WriteResponse")

	log.Println(log.TRACE, pretty.Sprintf("RPC Server Writing ResponseHeader %s %+v", reflect.TypeOf(rs), rs))

	err = sc.Encoder.Encode(rs)
	if err != nil {
		log.Println(log.ERROR, "RPC Server Error encoding rpc response: ", err)
		sc.Close()
		return
	}

	log.Println(log.TRACE, pretty.Sprintf("RPC Server Writing Response Value %s %+v", reflect.TypeOf(v), v))

	err = sc.Encoder.Encode(v)
	if err != nil {
		log.Println(log.ERROR, "RPC Server Error encoding response value: ", err)
		sc.Close()
		return
	}

	return
}
Esempio n. 10
0
func (sc *ServerCodec) ReadRequestHeader(rq *rpc.Request) (err error) {
	log.Println(log.TRACE, "RPC Server Entered: ReadRequestHeader")
	defer log.Println(log.TRACE, "RPC Server Leaving: ReadRequestHeader")

	err = sc.Decoder.Decode(rq)
	if err != nil && err != io.EOF {
		log.Println(log.ERROR, "RPC Server Error decoding request header: ", err)
		sc.Close()
	}

	if err == nil {
		log.Println(log.TRACE, pretty.Sprintf("RPC Server Read RequestHeader %s %+v", reflect.TypeOf(rq), rq))
	}
	return
}
Esempio n. 11
0
func (cc *ClientCodec) ReadResponseHeader(res *rpc.Response) (err error) {
	log.Println(log.TRACE, "RPC Client Entered: ReadResponseHeader")
	defer log.Println(log.TRACE, "RPC Client Leaving: ReadResponseHeader")

	err = cc.Decoder.Decode(res)

	if err != nil {
		cc.Close()
		log.Println(log.ERROR, "RPC Client Error decoding response header: ", err)
	}

	if err == nil {
		log.Println(log.TRACE, pretty.Sprintf("RPC Client Read ResponseHeader %s %+v", reflect.TypeOf(res), res))
	}

	return
}
Esempio n. 12
0
func (cc *ClientCodec) ReadResponseBody(v interface{}) (err error) {
	log.Println(log.TRACE, "RPC Client Entered: ReadResponseBody")
	defer log.Println(log.TRACE, "RPC Client Leaving: ReadResponseBody")

	if v == nil {
		err = errors.New("Response object cannot be nil")
		log.Println(log.ERROR, "RPC Client Error reading response body: ", err)
		return
	}

	err = cc.Decoder.Decode(v)

	if err != nil {
		cc.Close()
		log.Println(log.ERROR, "RPC Client Error decoding response body: ", err)
	}

	if err == nil {
		log.Println(log.TRACE, pretty.Sprintf("RPC Client Read ResponseBody %s %+v", reflect.TypeOf(v), v))
	}
	return
}
Esempio n. 13
0
func main() {
	resp, err := http.Get(fmt.Sprintf("https://github.com/users/%s/contributions", user))
	if err != nil {
		logger.Fatalf("Could not retrieve github data: %s", err)
	}

	doc, err := goquery.NewDocumentFromResponse(resp)
	if err != nil {
		logger.Fatal("Could not parse returned XML: %s", err)
	}

	startdate := getFirstFullDate(doc)
	logger.Debugf("Got first available full-column date: %s", startdate)

	multiplier := getHighestCommitCount(doc) / 3 * 2
	logger.Debugf("Multiplier set to: %v", multiplier)

	//Get the letter arrays from the string
	symbols := StringToPixelSymbols(text)
	logger.Debugf("Converted string %s to symbols: \n%s", text, pretty.Sprintf("%s", symbols))

	//Build and print the script to stdout
	fmt.Println(buildScript(user, repo, text, multiplier, startdate, symbols))
}
func (e TransformError) Error() string {
	return pretty.Sprintf("%v", e.What)
}
Esempio n. 15
0
package main

import (
	"fmt"
	"github.com/hkwi/nlgo"
	"github.com/kr/pretty"
	"github.com/shiaho/netlink_tool/netlink"
	"io/ioutil"
	"strconv"
	"syscall"
	"time"
)

var (
	_            = pretty.Sprintf("")
	taskstatsMap = make(map[int]*netlink.Taskstats)
)

func main() {
	nlsk := nlgo.NlSocketAlloc()
	nlgo.NlConnect(nlsk, syscall.NETLINK_GENERIC)
	familyID := uint16(22)
	fmt.Println(familyID)
	files, _ := ioutil.ReadDir("/proc/")
	var pids []int
	for _, f := range files {
		if f.Name()[0] >= '0' && f.Name()[0] <= '9' {
			pid, _ := strconv.ParseInt(f.Name(), 10, 32)
			pids = append(pids, int(pid))
		}
	}
Esempio n. 16
0
func Prettify(obj interface{}) string {
	return pretty.Sprintf("%# v", obj)
}
Esempio n. 17
0
/*
Conn.SendTimeout() Acts like Send but takes a timeout
*/
func (c *Conn) SendTimeout(ri *skynet.RequestInfo, fn string, in interface{}, out interface{}, timeout time.Duration) (err error) {
	if c.IsClosed() {
		return ConnectionClosed
	}

	sin := skynet.ServiceRPCInWrite{
		RequestInfo: ri,
		Method:      fn,
		ClientID:    c.clientID,
	}

	var b []byte
	b, err = bson.Marshal(in)
	if err != nil {
		return serviceError{fmt.Sprintf("Error calling bson.Marshal: %v", err)}
	}

	sin.In = bson.Binary{
		0x00,
		b,
	}

	type Resp struct {
		Out skynet.ServiceRPCOutRead
		Err error
	}

	respChan := make(chan *Resp)

	go func() {
		log.Println(log.TRACE, fmt.Sprintf("Sending Method call %s with ClientID %s to: %s", sin.Method, sin.ClientID, c.addr))
		r := &Resp{}

		r.Err = c.rpcClient.Call(c.serviceName+".Forward", sin, &r.Out)
		log.Println(log.TRACE, fmt.Sprintf("Method call %s with ClientID %s from: %s completed", sin.Method, sin.ClientID, c.addr))

		respChan <- r
	}()

	var r *Resp

	if timeout == 0 {
		timeout = 15 * time.Minute
	}

	t := time.After(timeout)

	select {
	case r = <-respChan:
		if r.Err != nil {
			err = serviceError{r.Err.Error()}
			c.Close()
			return
		}
	case <-t:
		err = fmt.Errorf("Connection: timing out request after %s", timeout.String())
		c.Close()
		return
	}

	if r.Out.ErrString != "" {
		err = serviceError{r.Out.ErrString}
		return
	}

	err = bson.Unmarshal(r.Out.Out, out)
	if err != nil {
		log.Println(log.ERROR, "Error unmarshalling nested document")
		err = serviceError{err.Error()}
		c.Close()
	}

	log.Println(log.TRACE, pretty.Sprintf("Method call %s with ClientID %s from: %s returned: %s %+v", sin.Method, sin.ClientID, c.addr, reflect.TypeOf(out), out))

	return
}
Esempio n. 18
0
func FDumpVars(args ...interface{}) string {
	return pretty.Sprintf("%# v", args)
}
Esempio n. 19
0
func (c *Strings) String() string {
	return pretty.Sprintf("%v", []string(*c))
}
func (e TransitRouterError) Error() string {
	return pretty.Sprintf("%v", e.What)
}