This is an automated email from the ASF dual-hosted git repository.
zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git
The following commit(s) were added to refs/heads/master by this push:
new 9a7f6aad Initial horus framework (#321)
9a7f6aad is described below
commit 9a7f6aad52c2e735b129e32833b11eaa13cf8822
Author: mfordjody <[email protected]>
AuthorDate: Fri Sep 6 13:48:04 2024 +0800
Initial horus framework (#321)
Add license header
---
app/horus/basic/config/file.go | 27 ++++++++++++++++++++
app/horus/basic/config/flag.go | 44 +++++++++++++++++++++++++++++++
app/horus/basic/group/group.go | 54 +++++++++++++++++++++++++++++++++++++++
app/horus/cmd/main.go | 41 +++++++++++++++++++++++++++++
app/horus/core/manager/manager.go | 27 ++++++++++++++++++++
5 files changed, 193 insertions(+)
diff --git a/app/horus/basic/config/file.go b/app/horus/basic/config/file.go
new file mode 100644
index 00000000..23f2f7dc
--- /dev/null
+++ b/app/horus/basic/config/file.go
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+type Config struct {
+ HttpAddr string `yaml:"HttpAddr"`
+ Mysql *Mysql `yaml:"Mysql"`
+}
+
+type Mysql struct {
+ Name string `yaml:"Name"`
+ Addr string `yaml:"Addr"`
+ Debug bool `yaml:"Debug"`
+}
diff --git a/app/horus/basic/config/flag.go b/app/horus/basic/config/flag.go
new file mode 100644
index 00000000..a10eeeb6
--- /dev/null
+++ b/app/horus/basic/config/flag.go
@@ -0,0 +1,44 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+import (
+ "fmt"
+ "gopkg.in/yaml.v2"
+ "os"
+)
+
+func Load(in string) (*Config, error) {
+ cfg := &Config{}
+ err := yaml.Unmarshal([]byte(in), cfg)
+ if err != nil {
+ return nil, err
+ }
+ return cfg, err
+}
+
+func LoadFile(name string) (*Config, error) {
+ bytes, err := os.ReadFile(name)
+ if err != nil {
+ return nil, err
+ }
+ cfg, err := Load(string(bytes))
+ if err != nil {
+ fmt.Printf("parsing YAML file err:%v", err)
+ return nil, err
+ }
+ return cfg, err
+}
diff --git a/app/horus/basic/group/group.go b/app/horus/basic/group/group.go
new file mode 100644
index 00000000..1a66db71
--- /dev/null
+++ b/app/horus/basic/group/group.go
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package group
+
+import (
+ "os"
+ "os/signal"
+ "sync"
+ "syscall"
+)
+
+type WaitGroup struct {
+ wg sync.WaitGroup
+}
+
+func (g *WaitGroup) Add(f func() error) {
+ g.wg.Add(1)
+ go func() {
+ defer g.wg.Done()
+ err := f()
+ if err != nil {
+ return
+ }
+ }()
+}
+
+func (g *WaitGroup) Wait() {
+ g.wg.Wait()
+}
+
+func (g *WaitGroup) SetupStopChanWithContext() (*WaitGroup, chan struct{}) {
+ stopChan := make(chan struct{})
+ SignalChan := make(chan os.Signal, 1)
+ signal.Notify(SignalChan, syscall.SIGTERM, syscall.SIGQUIT)
+ g.Add(func() error {
+ <-stopChan
+ close(stopChan)
+ return nil
+ })
+ return g, stopChan
+}
diff --git a/app/horus/cmd/main.go b/app/horus/cmd/main.go
new file mode 100644
index 00000000..98c631e9
--- /dev/null
+++ b/app/horus/cmd/main.go
@@ -0,0 +1,41 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "flag"
+ "github.com/apache/dubbo-kubernetes/app/horus/basic/config"
+ "k8s.io/klog/v2"
+)
+
+var (
+ httpAddr string
+ configFile string
+)
+
+func main() {
+ flag.StringVar(&configFile, "configFile", "./horus.yaml", "horus config
file")
+ flag.StringVar(&httpAddr, "httpAddr", "0.0.0.0:9089", "horus http addr")
+ flag.Parse()
+
+ c, err := config.LoadFile(configFile)
+ if err != nil {
+ klog.Infof("load config file success.")
+ } else {
+ klog.Errorf("load config file failed err: %v", c)
+ return
+ }
+}
diff --git a/app/horus/core/manager/manager.go
b/app/horus/core/manager/manager.go
new file mode 100644
index 00000000..ccd384d4
--- /dev/null
+++ b/app/horus/core/manager/manager.go
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package manager
+
+type Manager struct {
+ httpAddr string
+}
+
+func NewManager(httpAddr string) *Manager {
+ pm := &Manager{
+ httpAddr: httpAddr,
+ }
+ return pm
+}