Commit 23e31e79 authored by ibuler's avatar ibuler

[Update] 修改一些结构

parent 216880ee
......@@ -14,4 +14,5 @@ data/
log/
go.sum
.idea/
vendor/
\ No newline at end of file
vendor/
config.yml
\ No newline at end of file
NAME: coco2
BOOTSTRAP_TOKEN: PleaseChangeMe
CORE_HOST: http://127.0.0.1:8080
......@@ -2,21 +2,40 @@ package config
import (
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
Name string `yaml:"NAME"`
CoreHost string `yaml:"CORE_HOST"`
BootstrapToken string `yaml:"BOOTSTRAP_TOKEN"`
BindHost string `yaml:"BIND_HOST"`
SshPort int `yaml:"SSHD_PORT"`
HTTPPort int `yaml:"HTTPD_PORT"`
CustomerAccessKey string `yaml:"ACCESS_KEY"`
AccessKeyFile string `yaml:"ACCESS_KEY_FILE"`
LogLevel string `yaml:"LOG_LEVEL"`
HeartBeat int `yaml:"HEARTBEAT_INTERVAL"`
RootPath string
Comment string
TermConfig *TerminalConfig
}
func LoadFromYaml(filepath string) *Config {
c := createDefaultConfig()
body, err := ioutil.ReadFile(filepath)
if err != nil {
log.Errorf("Not found file: %s", filepath)
os.Exit(1)
}
e := yaml.Unmarshal(body, &c)
if e != nil {
fmt.Println("load yaml err")
fmt.Println("Load yaml err")
os.Exit(1)
}
return &c
......@@ -42,21 +61,7 @@ func createDefaultConfig() Config {
}
}
type Config struct {
Name string `yaml:"NAME"`
CoreHost string `yaml:"CORE_HOST"`
BootstrapToken string `yaml:"BOOTSTRAP_TOKEN"`
BindHost string `yaml:"BIND_HOST"`
SshPort int `yaml:"SSHD_PORT"`
HTTPPort int `yaml:"HTTPD_PORT"`
CustomerAccessKey string `yaml:"ACCESS_KEY"`
AccessKeyFile string `yaml:"ACCESS_KEY_FILE"`
LogLevel string `yaml:"LOG_LEVEL"`
HeartBeat int `yaml:"HEARTBEAT_INTERVAL"`
RootPath string
Comment string
TermConfig *TerminalConfig
}
type TerminalConfig struct {
AssetListPageSize string `json:"TERMINAL_ASSET_LIST_PAGE_SIZE"`
......
# 数据层
\ No newline at end of file
# SDK层
\ No newline at end of file
package service
package service
......@@ -43,7 +43,7 @@ func Initial(config *config.Config, service *auth.Service) {
}
func StartServer() {
ser := ssh.Server{
srv := ssh.Server{
Addr: conf.BindHost + ":" + strconv.Itoa(conf.SshPort),
PasswordHandler: appService.CheckSSHPassword,
PublicKeyHandler: appService.CheckSSHPublicKey,
......@@ -51,7 +51,7 @@ func StartServer() {
Version: "coco-v1.4",
Handler: connectHandler,
}
log.Fatal(ser.ListenAndServe())
log.Fatal(srv.ListenAndServe())
}
func connectHandler(sess ssh.Session) {
......
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