Skip to content

Commit

Permalink
Merge pull request #366 from pratikmota/pipes-part-5
Browse files Browse the repository at this point in the history
[pipes-functions] Adding get and post function
  • Loading branch information
refaktor authored Oct 3, 2024
2 parents 8090a94 + e57b057 commit 26b4df1
Showing 1 changed file with 50 additions and 1 deletion.
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

}

0 comments on commit 26b4df1

Please sign in to comment.