func scriptBody(sessionId []byte, graphName, script string, bindings map[string]interface{}) (out []byte, err error) { var ( mh = new(codec.MsgpackHandle) enc = codec.NewEncoderBytes(&out, mh) reqId = uuid.NewV4() isSessionless = bytes.Equal(sessionId, sessionlessUuid[:]) ) mh.MapType = reflect.TypeOf(map[string]interface{}(nil)) meta := map[string]interface{}{ "inSession": !isSessionless, "isolate": isSessionless, "graphObjName": "g", } if isSessionless { meta["graphName"] = graphName } err = enc.Encode([]interface{}{ sessionId, reqId[:], meta, "groovy", script, bindings, }) return }
func AddScreenshot(screenshot *operations.AddScreenshotParams) error { query := `insert into pictures (learning_resource_id, picture_url) values($1, $2)` buf, err := ioutil.ReadAll(screenshot.Screenshot.Data) if err != nil { return err } u1 := uuid.NewV4() ioutil.WriteFile("./public/screenshots/"+u1.String()+".png", buf, 0644) url := "https://boolmeover.com/screenshots/" + u1.String() + ".png" _, err = db.Exec(query, screenshot.ID, url) if err != nil { return err } return nil }
func (s *session) sessionBody(kill bool) (out []byte, err error) { var ( mh = new(codec.MsgpackHandle) enc = codec.NewEncoderBytes(&out, mh) reqId = uuid.NewV4() ) mh.MapType = reflect.TypeOf(map[string]interface{}(nil)) err = enc.Encode([]interface{}{ s.sId, reqId[:], map[string]interface{}{ "graphName": s.r.graphName, "graphObjName": "g", "killSession": kill, }, s.username, s.password, }) return }
func main() { flag.Parse() conn, err := grpc.Dial(*server) if err != nil { panic(fmt.Sprintln("fail to dial: %v", err)) } defer conn.Close() client := proto.NewEventServiceClient(conn) me, err := user.Current() if err != nil { panic(fmt.Sprintln("unable to lookup user: %v", err)) } // Since the client ID should be unique, generate one from the local user // (for tracing) and UUID. request := proto.StreamEventsRequest{ fmt.Sprintf("maelcat:%v:%v", me.Username, uuid.NewV4())} stream, err := client.StreamEvents(context.Background(), &request) if err != nil { panic(fmt.Sprintln("failed to start stream: %v", err)) } for { event, err := stream.Recv() if err == io.EOF { break } if err != nil { panic(fmt.Sprintln("stream error: %v", err)) } fmt.Println(event) } }