Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pipes-functions] Adding get and post function #366

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion evaldo/builtins_pipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ var Builtins_pipes = map[string]*env.Builtin{
if closeErr != nil {
return *env.NewError("Error closing pipe")
}
return nil
return *env.NewInteger(0)
default:
return MakeNativeArgError(ps, 1, []string{"script-pipe"}, "p-close")
}
Expand All @@ -800,6 +800,55 @@ var Builtins_pipes = map[string]*env.Builtin{
}
},
},

"get": {
Argsn: 2,
Doc: "Get makes an HTTP GET request to url, sending the contents of the pipe as the request body, and produces the server's response.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch p := arg0.(type) {
case env.Native:
switch pipe := p.Value.(type) {
case *script.Pipe:
switch s := arg1.(type) {
case env.String:
newPipe := pipe.Get(s.Value)
return *env.NewNative(ps.Idx, newPipe, "script-pipe")
default:
return MakeArgError(ps, 2, []env.Type{env.StringType}, "p-get")
}
default:
return MakeNativeArgError(ps, 1, []string{"script-pipe"}, "p-get")
}
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "p-get")
}
},
},

"post": {
Argsn: 2,
Doc: "Post makes an HTTP POST request to url, using the contents of the pipe as the request body, and produces the server's response.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch p := arg0.(type) {
case env.Native:
switch pipe := p.Value.(type) {
case *script.Pipe:
switch s := arg1.(type) {
case env.String:
newPipe := pipe.Post(s.Value)
return *env.NewNative(ps.Idx, newPipe, "script-pipe")
default:
return MakeArgError(ps, 2, []env.Type{env.StringType}, "p-post")
}
default:
return MakeNativeArgError(ps, 1, []string{"script-pipe"}, "p-post")
}
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "p-post")
}
},
},

// GOPSUTIL

}