Skip to content

Commit

Permalink
Initial horus framework (#321)
Browse files Browse the repository at this point in the history
Add license header
  • Loading branch information
mfordjody authored Sep 6, 2024
1 parent 92d9790 commit 9a7f6aa
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/horus/basic/config/file.go
Original file line number Diff line number Diff line change
@@ -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"`
}
44 changes: 44 additions & 0 deletions app/horus/basic/config/flag.go
Original file line number Diff line number Diff line change
@@ -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
}
54 changes: 54 additions & 0 deletions app/horus/basic/group/group.go
Original file line number Diff line number Diff line change
@@ -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
}
41 changes: 41 additions & 0 deletions app/horus/cmd/main.go
Original file line number Diff line number Diff line change
@@ -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
}
}
27 changes: 27 additions & 0 deletions app/horus/core/manager/manager.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9a7f6aa

Please sign in to comment.