-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
223 additions
and
26 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,36 @@ | ||
// Copyright 2018 The QOS Authors | ||
|
||
package commands | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/QOSGroup/qmoon/db" | ||
"github.com/QOSGroup/qmoon/service" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// DoctorCmd 健康检查 | ||
var DoctorCmd = &cobra.Command{ | ||
Use: "doctor", | ||
Short: "健康检查", | ||
RunE: doctor, | ||
} | ||
|
||
func init() { | ||
registerFlagsDb(DoctorCmd) | ||
} | ||
|
||
func doctor(cmd *cobra.Command, args []string) error { | ||
err := db.InitDb(config.DB, logger) | ||
if err != nil { | ||
log.Printf("Check db fail err:%s", err.Error()) | ||
} | ||
|
||
err = service.Doctor() | ||
if err != nil { | ||
log.Printf("Check env fail err:%s", err.Error()) | ||
} | ||
|
||
return nil | ||
} |
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
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
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
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
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,52 @@ | ||
// Copyright 2018 The QOS Authors | ||
|
||
package atm | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/QOSGroup/qstars/x/bank" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/tendermint/go-amino" | ||
tmltypes "github.com/tendermint/tendermint/rpc/lib/types" | ||
) | ||
|
||
func TestSend(t *testing.T) { | ||
//logrus.SetLevel(logrus.DebugLevel) | ||
//logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
//addr := "address1pcjs0t9m9vl7vejwttuc2fzfgnutndnrpyw08m" | ||
//chainid := "capricorn-1000" | ||
//coin := "qos" | ||
//amount := getAmount() | ||
//_, err := send(addr, chainid, fmt.Sprintf("%d%s", amount, coin)) | ||
//assert.Nil(t, err) | ||
} | ||
|
||
func TestJson(t *testing.T) { | ||
body := `{ | ||
"jsonrpc": "2.0", | ||
"id": "", | ||
"result": { | ||
"hash": "1CFC7C08C9E3CB6F8DF7E8668BEABDEA55022237", | ||
"error": "", | ||
"code": "-1", | ||
"result": "BankStub", | ||
"heigth": "374095" | ||
} | ||
}` | ||
|
||
var tmresp tmltypes.RPCResponse | ||
fmt.Println(string(body)) | ||
err := json.Unmarshal([]byte(body), &tmresp) | ||
assert.Nil(t, err) | ||
|
||
assert.True(t, tmresp.Error == nil) | ||
var res bank.SendResult | ||
var cdc = amino.NewCodec() | ||
err = cdc.UnmarshalJSON(tmresp.Result, &res) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "1CFC7C08C9E3CB6F8DF7E8668BEABDEA55022237", res.Hash) | ||
assert.Equal(t, "374095", res.Heigth) | ||
} |
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
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
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,55 @@ | ||
// Copyright 2018 The QOS Authors | ||
|
||
package service | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/QOSGroup/qmoon/plugins" | ||
) | ||
|
||
type Env struct { | ||
EmailSmtpServer string | ||
EmailUser string | ||
EmailPassword string | ||
} | ||
|
||
var env *Env | ||
|
||
func GetEnv() Env { | ||
if env == nil { | ||
env = new(Env) | ||
env.EmailSmtpServer = os.Getenv("MailSmtpServer") | ||
env.EmailUser = os.Getenv("MailUser") | ||
env.EmailPassword = os.Getenv("MailPassword") | ||
} | ||
|
||
return *env | ||
} | ||
|
||
func Doctor() error { | ||
if err := CheckEnv(); err != nil { | ||
return err | ||
} | ||
|
||
if err := plugins.Doctor(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func CheckEnv() error { | ||
if env.EmailPassword == "" { | ||
return errors.New("MailSmtpServer 未设置") | ||
} | ||
if env.EmailUser == "" { | ||
return errors.New("EmailUser 未设置") | ||
} | ||
if env.EmailPassword == "" { | ||
return errors.New("EmailPassword 未设置") | ||
} | ||
|
||
return nil | ||
} |
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
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,9 @@ | ||
// Copyright 2018 The QOS Authors | ||
|
||
package utils | ||
|
||
import "time" | ||
|
||
func DayStart(t time.Time) time.Time { | ||
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local) | ||
} |