func MakeRequestWithOptions()

in gdbclient/internal/graphsonv3/writer.go [65:109]


func MakeRequestWithOptions(gremlin string, options *graph.RequestOptions) (*Request, error) {
	request := &Request{Op: graph.OPS_EVAL, Args: make(map[string]interface{})}

	// override requestId
	if options != nil {
		request.RequestID = options.GetOverrideRequestId()
	}
	if request.RequestID == "" {
		if id, err := GenUUID(); err != nil {
			return nil, err
		} else {
			request.RequestID = id.String()
		}
	}
	// set specific configurations
	request.Args[graph.ARGS_GREMLIN] = gremlin
	request.Args[graph.ARGS_LANGUAGE] = "gremlin-groovy"

	// send request now if options is nil
	if options == nil {
		return request, nil
	}

	// set optional args if they were made available
	if timeout := options.GetTimeout(); timeout > 0 {
		request.Args[graph.ARGS_SCRIPT_EVAL_TIMEOUT] = timeout
	}

	session := false
	if args := options.GetArgs(); args != nil && len(args) > 0 {
		for k, v := range args {
			request.Args[k] = v
			if k == graph.ARGS_SESSION {
				session = true
			}
		}
	}
	// set 'session' processor if choose session mode
	if session {
		request.Processor = "session"
	}

	//internal.Logger.Info("request", zap.String("id", request.RequestID), zap.Bool("session", session))
	return request, nil
}