Skip to content

Commit

Permalink
feat: add artifact APIs (#221)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Jan 31, 2024
1 parent 39fb963 commit 4038000
Show file tree
Hide file tree
Showing 7 changed files with 1,049 additions and 613 deletions.
16 changes: 16 additions & 0 deletions pkg/service/client_kclvm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ func (p *KclvmServiceClient) ExecProgram(args *gpyrpc.ExecProgram_Args) (resp *g
return
}

func (p *KclvmServiceClient) BuildProgram(args *gpyrpc.BuildProgram_Args) (resp *gpyrpc.BuildProgram_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).BuildProgram(args)
err = p.wrapErr(err, stderr)
})
return
}

func (p *KclvmServiceClient) ExecArtifact(args *gpyrpc.ExecArtifact_Args) (resp *gpyrpc.ExecProgram_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).ExecArtifact(args)
err = p.wrapErr(err, stderr)
})
return
}

func (p *KclvmServiceClient) ParseFile(args *gpyrpc.ParseFile_Args) (resp *gpyrpc.ParseFile_Result, err error) {
p.Runtime.DoTask(func(c *rpc.Client, stderr io.Reader) {
resp, err = p.getClient(c).ParseFile(args)
Expand Down
6 changes: 6 additions & 0 deletions pkg/service/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (p *_KclvmServiceImpl) Ping(ctx context.Context, args *gpyrpc.Ping_Args) (*
func (p *_KclvmServiceImpl) ExecProgram(ctx context.Context, args *gpyrpc.ExecProgram_Args) (*gpyrpc.ExecProgram_Result, error) {
return p.c.ExecProgram(args)
}
func (p *_KclvmServiceImpl) BuildProgram(ctx context.Context, args *gpyrpc.BuildProgram_Args) (*gpyrpc.BuildProgram_Result, error) {
return p.c.BuildProgram(args)
}
func (p *_KclvmServiceImpl) ExecArtifact(ctx context.Context, args *gpyrpc.ExecArtifact_Args) (*gpyrpc.ExecProgram_Result, error) {
return p.c.ExecArtifact(args)
}
func (p *_KclvmServiceImpl) ParseFile(ctx context.Context, args *gpyrpc.ParseFile_Args) (*gpyrpc.ParseFile_Result, error) {
return p.c.ParseFile(args)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/kclvm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "kcl-lang.io/kcl-go/pkg/spec/gpyrpc"
type KclvmService interface {
Ping(in *gpyrpc.Ping_Args) (out *gpyrpc.Ping_Result, err error)
ExecProgram(in *gpyrpc.ExecProgram_Args) (out *gpyrpc.ExecProgram_Result, err error)
BuildProgram(in *gpyrpc.BuildProgram_Args) (out *gpyrpc.BuildProgram_Result, err error)
ExecArtifact(in *gpyrpc.ExecArtifact_Args) (out *gpyrpc.ExecProgram_Result, err error)
ParseFile(in *gpyrpc.ParseFile_Args) (out *gpyrpc.ParseFile_Result, err error)
ParseProgram(in *gpyrpc.ParseProgram_Args) (out *gpyrpc.ParseProgram_Result, err error)
LoadPackage(in *gpyrpc.LoadPackage_Args) (out *gpyrpc.LoadPackage_Result, err error)
Expand Down
18 changes: 18 additions & 0 deletions pkg/service/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (p *restServer) initHttpRrouter() {
p.router.GET("/api:protorpc/BuiltinService.ListMethod", p.handle_ListMethod)

p.router.GET("/api:protorpc/KclvmService.ExecProgram", p.handle_ExecProgram)
p.router.GET("/api:protorpc/KclvmService.BuildProgram", p.handle_BuildProgram)
p.router.GET("/api:protorpc/KclvmService.ExecArtifact", p.handle_ExecArtifact)
p.router.GET("/api:protorpc/KclvmService.ParseFile", p.handle_ParseFile)
p.router.GET("/api:protorpc/KclvmService.ParseProgram", p.handle_ParseProgram)
p.router.GET("/api:protorpc/KclvmService.LoadPackage", p.handle_LoadPackage)
Expand All @@ -74,6 +76,8 @@ func (p *restServer) initHttpRrouter() {
p.router.POST("/api:protorpc/BuiltinService.ListMethod", p.handle_ListMethod)

p.router.POST("/api:protorpc/KclvmService.ExecProgram", p.handle_ExecProgram)
p.router.POST("/api:protorpc/KclvmService.BuildProgram", p.handle_BuildProgram)
p.router.POST("/api:protorpc/KclvmService.ExecArtifact", p.handle_ExecArtifact)
p.router.POST("/api:protorpc/KclvmService.ParseFile", p.handle_ParseFile)
p.router.POST("/api:protorpc/KclvmService.ParseProgram", p.handle_ParseProgram)
p.router.POST("/api:protorpc/KclvmService.LoadPackage", p.handle_LoadPackage)
Expand Down Expand Up @@ -146,6 +150,20 @@ func (p *restServer) handle_ExecProgram(w http.ResponseWriter, r *http.Request,
})
}

func (p *restServer) handle_BuildProgram(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var args = new(gpyrpc.BuildProgram_Args)
p.handle(w, r, args, func() (proto.Message, error) {
return p.c.BuildProgram(args)
})
}

func (p *restServer) handle_ExecArtifact(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var args = new(gpyrpc.ExecArtifact_Args)
p.handle(w, r, args, func() (proto.Message, error) {
return p.c.ExecArtifact(args)
})
}

func (p *restServer) handle_ParseFile(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var args = new(gpyrpc.ParseFile_Args)
p.handle(w, r, args, func() (proto.Message, error) {
Expand Down
Loading

0 comments on commit 4038000

Please sign in to comment.