From 6e7f43dfdd18996d4aa6fb0ea7d2802fb8b2161f Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Mon, 3 Jul 2023 10:42:43 +0800 Subject: [PATCH] thinking 1 level --- brain.go | 14 +++++++++++++- config.go | 5 +++++ state.go | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 config.go create mode 100644 state.go diff --git a/brain.go b/brain.go index 70f3a6e..566b5ff 100644 --- a/brain.go +++ b/brain.go @@ -2,14 +2,26 @@ package brain import ( context "context" + "log" + "sync/atomic" "github.com/474420502/brain/pb" ) // UnimplementedBrainServiceServer can be embedded to have forward compatible implementations. type BrainService struct { + IsRunningMain atomic.Int64 } -func (*BrainService) Add(context.Context, *pb.Request) (*pb.Response, error) { +func (brain *BrainService) Main() { + if brain.IsRunningMain.CompareAndSwap(0, 1) { + defer brain.IsRunningMain.Swap(0) + + } else { + log.Println("Main is Running") + } +} + +func (*BrainService) Add(cxt context.Context, req *pb.Request) (*pb.Response, error) { return &pb.Response{Code: 200}, nil } diff --git a/config.go b/config.go new file mode 100644 index 0000000..accd1a9 --- /dev/null +++ b/config.go @@ -0,0 +1,5 @@ +package brain + +// Config 配置 +type Config struct { +} diff --git a/state.go b/state.go new file mode 100644 index 0000000..eff880f --- /dev/null +++ b/state.go @@ -0,0 +1,4 @@ +package brain + +type State struct { +}