-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a4138c
commit 5fbb867
Showing
25 changed files
with
531 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2018-2020 Double All rights reserved. | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
package modules | ||
|
||
import ( | ||
"path" | ||
|
||
"github.com/2637309949/dolphin/cmd/dolphin/gen/pipe" | ||
"github.com/2637309949/dolphin/cmd/dolphin/gen/template" | ||
"github.com/2637309949/dolphin/cmd/dolphin/schema" | ||
"github.com/2637309949/dolphin/packages/viper" | ||
"github.com/shurcooL/httpfs/vfsutil" | ||
) | ||
|
||
// Proto struct | ||
type Proto struct { | ||
} | ||
|
||
// Name defined pipe name | ||
func (oa *Proto) Name() string { | ||
return "proto" | ||
} | ||
|
||
// Build func | ||
func (oa *Proto) Build(dir string, node *schema.Application) ([]*pipe.TmplCfg, error) { | ||
var tmplCfgs []*pipe.TmplCfg | ||
ctrByte, _ := vfsutil.ReadFile(template.Assets, "proto.tmpl") | ||
rpcByte, _ := vfsutil.ReadFile(template.Assets, "rpc.tmpl") | ||
for _, s := range node.Services { | ||
data := map[string]interface{}{ | ||
"PackageName": node.PackageName, | ||
"Name": node.Name, | ||
"Service": s, | ||
} | ||
tmplCfg := &pipe.TmplCfg{ | ||
Text: string(ctrByte), | ||
FilePath: path.Join(dir, viper.GetString("dir.rpc"), "proto", s.Name+".proto"), | ||
Data: data, | ||
Overlap: pipe.OverlapInc, | ||
GOFmt: false, | ||
GOProto: true, | ||
} | ||
tmplCfgs = append(tmplCfgs, tmplCfg) | ||
tmplCfg = &pipe.TmplCfg{ | ||
Text: string(rpcByte), | ||
FilePath: path.Join(dir, viper.GetString("dir.rpc"), s.Name+".go"), | ||
Data: data, | ||
Overlap: pipe.OverlapInc, | ||
GOFmt: true, | ||
} | ||
tmplCfgs = append(tmplCfgs, tmplCfg) | ||
} | ||
return tmplCfgs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Code generated by dol build. Only Generate by tools if not existed, your can rewrite platform.App default action | ||
// source: | ||
|
||
syntax = "proto3"; | ||
|
||
package proto; | ||
|
||
// {{.Service.ToUpperCase .Service.Name}} defined | ||
service {{.Service.ToUpperCase .Service.Name}} { | ||
{{- range .Service.RPCS}} | ||
rpc {{.ToUpperCase .Name}} ({{.PRef .Request.Type}}) returns ({{.PRef .Reply.Type}}) {} | ||
{{- end}} | ||
} | ||
|
||
{{range .Service.RPCS}} | ||
// {{.PRef .Request.Type}} defined | ||
message {{.PRef .Request.Type}} {} | ||
// {{.PRef .Reply.Type}} defined | ||
message {{.PRef .Reply.Type}} {} | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package rpc | ||
|
||
import ( | ||
"{{.PackageName}}/rpc/proto" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// {{.Service.ToUpperCase .Service.Name}} defined | ||
type {{.Service.ToUpperCase .Service.Name}} struct{} | ||
|
||
{{range .Service.RPCS}} | ||
// {{.ToUpperCase .Name}} defined | ||
func (s *{{$.Service.ToUpperCase $.Service.Name}}) {{.ToUpperCase .Name}}(ctx context.Context, in *proto.{{.PRef .Request.Type}}) (*proto.{{.PRef .Reply.Type}}, error) { | ||
return &proto.{{.PRef .Reply.Type}}{}, nil | ||
} | ||
{{end}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.