-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add license header
- Loading branch information
Showing
5 changed files
with
193 additions
and
0 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
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"` | ||
} |
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,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 | ||
} |
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,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 | ||
} |
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,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 | ||
} | ||
} |
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,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 | ||
} |