整理目录结构

pull/1/head
miraclesu 8 years ago
parent 1196bed1a2
commit 413254b9d2

@ -7,7 +7,6 @@ import (
"sunteng/commons/event"
"sunteng/commons/log"
"sunteng/cronsun"
"sunteng/cronsun/conf"
"sunteng/cronsun/web"
)
@ -15,7 +14,8 @@ import (
func main() {
l, err := net.Listen("tcp", conf.Config.Web.BindAddr)
if err != nil {
cronsun.Fatalln(err)
log.Error(err.Error())
return
}
// Create a cmux.
@ -23,7 +23,8 @@ func main() {
httpL := m.Match(cmux.HTTP1Fast())
httpServer, err := web.InitRouters()
if err != nil {
cronsun.Fatalln(err)
log.Error(err.Error())
return
}
go httpServer.Serve(httpL)

@ -1,4 +1,4 @@
{
BindAddr: ":7079",
UIDir: ""
"BindAddr": ":7079",
"UIDir": ""
}

@ -1,22 +0,0 @@
package cronsun
import (
"sunteng/cronsun/conf"
"github.com/coreos/etcd/clientv3"
)
var etcdClient *clientv3.Client
func EtcdInstance() (*clientv3.Client, error) {
if etcdClient != nil {
return etcdClient, nil
}
if err := conf.Init(); err != nil {
return nil, err
}
etcdClient, err := clientv3.New(conf.Config.Etcd)
return etcdClient, err
}

@ -1,4 +1,4 @@
package cronsun
package models
type Job struct {
Id string `json:"id"`

@ -1,4 +1,4 @@
package cronsun
package models
type Node struct {
Pid int `json:"pid"`

@ -4,6 +4,7 @@ import (
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
"path"
"sort"
@ -15,16 +16,28 @@ import (
"github.com/gorilla/mux"
"golang.org/x/net/context"
"fmt"
"sunteng/commons/log"
"sunteng/cronsun"
"sunteng/cronsun/conf"
"sunteng/cronsun/models"
)
var etcdClient *clientv3.Client
func EtcdInstance() (*clientv3.Client, error) {
if etcdClient != nil {
return etcdClient, nil
}
if err := conf.Init(); err != nil {
return nil, err
}
etcdClient, err := clientv3.New(conf.Config.Etcd)
return etcdClient, err
}
func InitRouters() (s *http.Server, err error) {
etcdClient, err = cronsun.EtcdInstance()
etcdClient, err = EtcdInstance()
if err != nil {
return nil, err
}
@ -91,9 +104,9 @@ func getJobsByGroupName(w http.ResponseWriter, r *http.Request) {
return
}
var jobList = make([]*cronsun.Job, 0, resp.Count)
var jobList = make([]*models.Job, 0, resp.Count)
for i := range resp.Kvs {
job := &cronsun.Job{}
job := &models.Job{}
err = json.Unmarshal(resp.Kvs[i].Value, &job)
if err != nil {
outJSONError(w, http.StatusInternalServerError, err.Error())
@ -106,7 +119,7 @@ func getJobsByGroupName(w http.ResponseWriter, r *http.Request) {
}
func updateJob(w http.ResponseWriter, r *http.Request) {
job := &cronsun.Job{}
job := &models.Job{}
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&job)
if err != nil {
@ -174,9 +187,9 @@ func getNodeGroupByName(w http.ResponseWriter, r *http.Request) {
return
}
var nodeList = make([]*cronsun.Node, 0, resp.Count)
var nodeList = make([]*models.Node, 0, resp.Count)
for i := range resp.Kvs {
node := &cronsun.Node{}
node := &models.Node{}
err = json.Unmarshal(resp.Kvs[i].Value, &node)
if err != nil {
outJSONError(w, http.StatusInternalServerError, err.Error())

Loading…
Cancel
Save