Exemple #1
0
func mapToBytes(in map[string]interface{}) (out []byte, err error) {
	cbor := new(codec.CborHandle)
	err = cborrpc.SetExts(cbor)
	if err != nil {
		return
	}
	encoder := codec.NewEncoderBytes(&out, cbor)
	err = encoder.Encode(in)
	return
}
Exemple #2
0
func bytesToMap(in []byte) (out map[string]interface{}, err error) {
	cbor := new(codec.CborHandle)
	err = cborrpc.SetExts(cbor)
	if err != nil {
		return
	}
	decoder := codec.NewDecoderBytes(in, cbor)
	err = decoder.Decode(&out)
	return
}
Exemple #3
0
func main() {
	var err error

	var namespace coordinate.Namespace
	bind := flag.String("bind", ":5932", "[ip]:port to listen on")
	backend := backend.Backend{Implementation: "memory", Address: ""}
	flag.Var(&backend, "backend", "impl[:address] of the storage backend")
	config := flag.String("config", "", "global configuration YAML file")
	flag.Parse()

	var gConfig map[string]interface{}
	if *config != "" {
		gConfig, err = loadConfigYaml(*config)
		if err != nil {
			panic(err)
		}
	}

	cbor := new(codec.CborHandle)
	coordinate, err := backend.Coordinate()
	if err == nil {
		namespace, err = coordinate.Namespace("")
	}
	if err == nil {
		err = cborrpc.SetExts(cbor)
	}
	if err != nil {
		panic(err)
	}
	jobd := &jobserver.JobServer{
		Namespace:    namespace,
		GlobalConfig: gConfig,
	}

	ln, err := net.Listen("tcp", *bind)
	if err != nil {
		fmt.Printf("Could not listen to %v: %v\n", *bind, err)
		return
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			fmt.Printf("Could not accept connection: %v\n", err)
			return
		}
		go handleConnection(conn, jobd, cbor)
	}
}