Commit cc8da8dd authored by Lei Li's avatar Lei Li
Browse files

feat: 增加基础框架

parent 7bd753b1
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/basic-plugin.iml" filepath="$PROJECT_DIR$/.idea/basic-plugin.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
.pre-build:
mkdir -p bin/
build: .pre-build
go build -gcflags='all=-N -l' -o bin/pushStreaming ./cmd
package main
import (
"basic-plugin/config"
"os"
"path/filepath"
"linkfog.com/pluginx/pluginrpc"
"linkfog.com/public/lib/l"
)
func main() {
pluginFuncs := map[string]PluginFunc{
"start": nil,
"stop": nil,
}
pluginServer := newServer(config.ServicePluginName, pluginFuncs)
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
l.Errorf(err)
os.Exit(1)
}
config.WorkDir = dir
grpcServer, err := pluginrpc.NewPluginGrpcServer(filepath.Join(config.WorkDir, config.SockFile), pluginServer)
if err != nil {
l.Errorf("error creating plugin grpc server: %v", err)
os.Exit(1)
}
defer grpcServer.Close()
select {}
}
package main
import (
"context"
"fmt"
"time"
pb "linkfog.com/pluginx/proto"
"linkfog.com/public/lib/l"
)
type PluginFunc func(req *pb.Req) (*pb.Res, error)
type pluginServer struct {
pb.UnimplementedPluginServer
pluginName string
pluginFuncs map[string]PluginFunc
}
func newServer(pluginName string, pluginFuncs map[string]PluginFunc) *pluginServer {
s := &pluginServer{
pluginName: pluginName,
pluginFuncs: pluginFuncs,
}
return s
}
func (s *pluginServer) Call(ctx context.Context, req *pb.Req) (*pb.Res, error) {
pluginName := req.Header.To
funcName := req.Header.Func
if pluginName != s.pluginName {
return nil, fmt.Errorf("mismatch plugin name %s, %s expected", pluginName, s.pluginName)
}
pluginFunc, ok := s.pluginFuncs[funcName]
if !ok {
return nil, fmt.Errorf("unknown plugin func %s", funcName)
}
start := time.Now()
res, err := pluginFunc(req)
if err != nil {
return res, fmt.Errorf("call plugin func %s err: %v", funcName, err)
}
l.Infof("call plugin func %s success, cost: %v", funcName, time.Since(start))
return res, nil
}
package config
var (
WorkDir = ""
SockFile = "pushStreaming.sock"
ServicePluginName = "pushStreaming"
)
module basic-plugin
go 1.23.2
replace linkfog.com/public => web.lueluesay.top/git/lil/public v0.0.0-20241017054747-f08bac907b6c
replace linkfog.com/pluginx => web.lueluesay.top/git/lil/pluginx v0.0.0-20241017112237-9affa4009a35
require (
linkfog.com/pluginx v0.0.0-00010101000000-000000000000
linkfog.com/public v0.0.0-00010101000000-000000000000
)
require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
web.lueluesay.top/git/lil/pluginx v0.0.0-20241017112237-9affa4009a35 h1:XgY8a7iuuwJqtzCzN50i9ZVzUhJFpp0BeaMAJgkvAj0=
web.lueluesay.top/git/lil/pluginx v0.0.0-20241017112237-9affa4009a35/go.mod h1:DL73qsfCIFfH2K6tdOLPj9tRcZ8AYxfPrkcTebYXr5o=
web.lueluesay.top/git/lil/public v0.0.0-20241017054747-f08bac907b6c h1:U/2ffmB20mPiC1GT0eTrc9GAQDCd2a8W4zAIb8wf1ds=
web.lueluesay.top/git/lil/public v0.0.0-20241017054747-f08bac907b6c/go.mod h1:x/nRP9pMRVToI9Te1TazybP0Qlj3V+/aA2EiPQEvzsI=
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment