Esempio n. 1
0
File: rpc.go Progetto: keysonZZZ/kmg
//TODO 对于不会发 RPC 的进程,应该可以用一个 flag 来表明不需要等待 RPC 响应
func waitRpcRespond() chan error {
	returnChan := make(chan error)
	lock := &kmgProcessMutex.FileMutex{Name: "kmg_service_lock"}
	lock.Lock()
	rpcCloser := ListenAndServe_ServiceRpc(rpcAddress, &ServiceRpc{}, rpcPsk)
	__closer := func() {
		err := rpcCloser()
		time.Sleep(time.Second)
		lock.UnLock()
		kmgErr.PanicIfError(err)
	}
	go func() {
		select {
		case startStatus := <-statusChannel:
			__closer()
			if startStatus == StartStatusSuccess {
				returnChan <- nil
			} else {
				returnChan <- errors.New("StartFail")
			}
		case <-time.After(time.Minute * 2):
			__closer()
			returnChan <- errors.New("Rpc timeout")
		}
	}()
	return returnChan
}
Esempio n. 2
0
func XSendMessage(message Message) (err error) {
	subMessageUrl := "https://api.submail.cn/message/xsend.json"
	kmgDebug.Println(message.Vars)
	response, err := http.PostForm(subMessageUrl, url.Values{
		"appid":     {MessageConfig.Appid},
		"signature": {MessageConfig.Signature},
		"to":        {message.To},
		"project":   {kmgStrconv.InterfaceToString(message.Project)},
		"vars":      {message.Vars},
	})
	defer response.Body.Close()
	if err != nil {
		return err
	}
	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return err
	}
	kmgLog.Log("SubMessage", string(body), message)
	data := kmgJson.MustUnmarshalToMapDeleteBOM(body)
	if data["status"] == "error" {
		return errors.New(kmgStrconv.InterfaceToString(data["msg"]))
	}
	return nil

}
Esempio n. 3
0
func SendMessage(massage Massege) (err error) {
	massegeApiUrl := "https://api.submail.cn/message/xsend"
	resp, e := http.PostForm(massegeApiUrl, url.Values{
		//		"appid":     {EmailConfig.Appid},
		//		"signature": {EmailConfig.Signature},
		"appid":     {"10111"},
		"signature": {"142a3e0d66c4dda1e918487b1952b26c"},
		"to":        {massage.To},
		"project":   {massage.ProjectId},
	})
	if e != nil {
		return e
	}
	defer resp.Body.Close()
	body, e := ioutil.ReadAll(resp.Body)
	if e != nil {
		return e
	}
	kmgLog.Log("Submail", string(body), massage)
	data := kmgJson.MustUnmarshalToMapDeleteBOM(body)
	if data["status"] == "error" {
		return errors.New(kmgStrconv.InterfaceToString(data["msg"]))
	}
	return nil
}
Esempio n. 4
0
func GetRepositoryFromPath(path string) (repo *Repository, err error) {
	p, err := kmgFile.SearchFileInParentDir(path, ".git")
	if err != nil {
		if err == kmgFile.NotFoundError {
			return nil, errors.New("can not found .git folder,do you in a git repository?")
		}
		return
	}
	return &Repository{
		gitPath: p,
	}, nil
}
Esempio n. 5
0
func parseInstallRequest() (s *Service, err error) {
	if len(os.Args) < 3 {
		return nil, errors.New("require name,exec args")
	}
	s = &Service{}
	s.Name = os.Args[1]
	s.CommandLineSlice = os.Args[2:]
	s.WorkingDirectory, err = os.Getwd()
	if err != nil {
		return
	}
	return
}
Esempio n. 6
0
func NewMultiErrorHandler(fs ...func() error) func() error {
	return func() error {
		var errS string
		for _, f := range fs {
			err1 := f()
			if err1 != nil {
				errS += "[" + err1.Error() + "] "
			}
		}
		if errS == "" {
			return nil
		}
		return errors.New(errS)
	}
}
Esempio n. 7
0
//返回当前机器上面的所有ip列表.没有ip会报错
func MustGetCurrentIpList() (ipList []net.IP) {
	if !kmgPlatform.IsLinux() {
		panic("[MustGetCurrentIpList] only support linux now")
	}
	deviceAddrList, err := GetCurrentDeviceAddr()
	if err != nil {
		panic(err)
	}
	if len(deviceAddrList) == 0 {
		panic(errors.New("[MustGetCurrentIpList] do not find any ip address."))
	}
	ipList = make([]net.IP, len(deviceAddrList))
	for i, addr := range deviceAddrList {
		ipList[i] = addr.IP
	}
	return ipList
}
Esempio n. 8
0
func MailBreack(email Mail, u url.Values, submailUrl string) (err error) {
	resp, e := http.PostForm(submailUrl, u)
	if e != nil {
		return e
	}
	defer resp.Body.Close()
	body, e := ioutil.ReadAll(resp.Body)
	if e != nil {
		return e
	}
	kmgLog.Log("Submail", string(body), email)
	data := kmgJson.MustUnmarshalToMapDeleteBOM(body)
	if data["status"] == "error" {
		return errors.New(kmgStrconv.InterfaceToString(data["msg"]))
	}
	return nil
}
Esempio n. 9
0
func MustGetCurrentIpWithPortList(port uint16) (sList []string) {
	if !kmgPlatform.IsLinux() {
		panic("[MustGetCurrentIpWithPortList] only support linux now")
	}
	deviceAddrList, err := GetCurrentDeviceAddr()
	if err != nil {
		panic(err)
	}
	if len(deviceAddrList) == 0 {
		panic(errors.New("[MustGetCurrentIpList] do not find any ip address."))
	}
	sList = make([]string, 0, len(deviceAddrList))
	sPort := strconv.Itoa(int(port))
	for _, addr := range deviceAddrList {
		ones, size := addr.IPNet.Mask.Size()
		if ones == size { // 实践表明 不能监听这种子网只有一个ip的地址.
			continue
		}
		sList = append(sList, net.JoinHostPort(addr.IP.String(), sPort))
	}
	return sList
}
Esempio n. 10
0
File: db.go Progetto: keysonZZZ/kmg
		if err != nil {
			return err
		}
		for _, key := range keyList {
			err = cb(key)
			if err != nil {
				return err
			}
		}
		if cursor == 0 {
			return nil
		}
	}
}

var scanWithOutputLimitEOFError = errors.New("scanWithOutputLimitEOFError")

// 保证只会返回小于等于limit个数据.
func ScanWithOutputLimit(pattern string, limit int) (sList []string, err error) {
	if limit == 0 {
		return nil, nil
	}
	sList = make([]string, 0, limit)
	err = ScanCallback(pattern, func(key string) error {
		sList = append(sList, key)
		if len(sList) >= limit {
			return scanWithOutputLimitEOFError
		} else {
			return nil
		}
	})
Esempio n. 11
0
package kmgFile

import (
	"os"
	"path/filepath"

	"github.com/bronze1man/kmg/errors"
)

var NotFoundError = errors.New("Not found")

//向上搜索某个目录下面的某个文件
// 比如搜索 .git 目录 搜索 .kmg.yml 文件
// 返回 .git 所在的上级目录.
func SearchFileInParentDir(startDirPath string, fileName string) (file string, err error) {
	startDirPath, err = filepath.Abs(startDirPath)
	if err != nil {
		return
	}
	p := startDirPath
	var kmgFilePath string
	for {
		kmgFilePath = filepath.Join(p, fileName)
		_, err = os.Stat(kmgFilePath)
		if err == nil {
			//found it
			return p, nil
		}
		if !os.IsNotExist(err) {
			return
		}
Esempio n. 12
0
File: err.go Progetto: keysonZZZ/kmg
package kmgQiniu

import "github.com/bronze1man/kmg/errors"

var ErrNoFile = errors.New("Not found file")
Esempio n. 13
0
	Android     SystemPlatform = "Android"
	IOS         SystemPlatform = "iOS"
	AllPlatform SystemPlatform = "AllPlatform"
)

func NewClient(req NewClientRequest) *Client {
	return &Client{
		c:            jpush.NewPushClient(req.Secret, req.AppKey),
		IsIosProduct: req.IsIosProduct,
		name:         req.Name,
		Platform:     req.Platform,
		IsActive:     req.IsActive,
	}
}

var NotFoundUser error = errors.New("[kmgJpush] user not exist")

func (c *Client) PushToOne(alias string, content string) (err error) {
	err = c.EasyPush(&JpushConfig{
		Alias:   alias,
		Content: content,
	})
	if err != nil {
		return err
	}
	return nil
}

func (c *Client) PushToTag(tag string, content string) (err error) {
	err = c.EasyPush(&JpushConfig{
		Tag:     tag,