Example #1
0
File: ke.go Project: kego/ke
func Open(ctx context.Context, filename string) (value interface{}, err error) {
	bytes, err := scanner.ProcessFile(filename)
	if err != nil {
		return nil, kerr.Wrap("HPWXWFTKWA", err)
	}
	err = system.Unmarshal(ctx, bytes, &value)
	if err != nil {
		return nil, kerr.Wrap("CXIULJCEBE", err)
	}
	return
}
Example #2
0
File: calls.go Project: kego/ke
func (s *Server) Data(request *shared.DataRequest, response *shared.DataResponse) error {
	if !s.auth.Auth([]byte(request.Path), request.Hash) {
		return kerr.New("SYEKLIUMVY", "Auth failed")
	}

	env, err := parser.ScanForEnv(s.ctx, request.Package)
	if err != nil {
		return kerr.Wrap("PNAGGKHDYL", err)
	}

	full, err := pkghelp.Check(env.Dir, request.File, env.Recursive)
	if err != nil {
		return kerr.Wrap("JEYTFWKMYF", err)
	}

	bytes, err := scanner.ProcessFile(full)
	if err != nil {
		return kerr.Wrap("HQXMIMWXFY", err)
	}
	if bytes == nil {
		return kerr.New("HIUINHIAPY", "Error reading %s", request.File)
	}

	localContext := envctx.NewContext(s.ctx, env)
	o := &system.ObjectStub{}
	if err := system.Unmarshal(localContext, bytes, o); err != nil {
		return kerr.Wrap("SVINFEMKBG", err)
	}
	if o.Id.Name != request.Name {
		return kerr.New("TNJSLMPMLB", "Id %s in %s does not match request %s", o.Id.Name, request.File, request.Name)
	}

	response.Package = request.Package
	response.Name = request.Name
	response.Found = true
	response.Data = bytes
	return nil
}