Browse Source

updated.

master
Mingcai SHEN 4 years ago
parent
commit
3aabe96349
8 changed files with 56 additions and 15 deletions
  1. +2
    -2
      auth/admin.go
  2. +9
    -0
      demo1/config.yaml
  3. +2
    -2
      demo1/models/models.go
  4. +2
    -2
      demo2/models/models.go
  5. +1
    -1
      go.mod
  6. +33
    -1
      mqtt/mqtt.go
  7. +1
    -1
      restlet/curd.go
  8. +6
    -6
      restlet/restlet.go

+ 2
- 2
auth/admin.go View File

@ -26,11 +26,11 @@ func Initialize(ctx restlet.TaskContext, params ...interface{}) error {
log.Fatalln("Create SCHEMA on database failed:>", e) log.Fatalln("Create SCHEMA on database failed:>", e)
return e return e
} }
if e := postgres.Initialize_HSTORE(ctx.SQL(), ctx.Schema()); nil != e {
if e := postgres.InitializeHSTORE(ctx.SQL(), ctx.Schema()); nil != e {
log.Fatalln("Initialize hstore on database failed:>", e) log.Fatalln("Initialize hstore on database failed:>", e)
return e return e
} }
if e := postgres.Initialize_UUID(ctx.SQL(), ctx.Schema()); nil != e {
if e := postgres.InitializeUUID(ctx.SQL(), ctx.Schema()); nil != e {
log.Fatalln("Initialize uuid on database failed:>", e) log.Fatalln("Initialize uuid on database failed:>", e)
return e return e
} }

+ 9
- 0
demo1/config.yaml View File

@ -31,6 +31,15 @@ subscribe:
address: "nsqd:4150" address: "nsqd:4150"
channel: default channel: default
mqtt:
server: ""
servers:
- ""
- ""
clientId: ""
username: ""
password: ""
logging: logging:
level: debug level: debug
format: plain format: plain

+ 2
- 2
demo1/models/models.go View File

@ -25,11 +25,11 @@ func Initialize(ctx restlet.TaskContext, params ...interface{}) error {
log.Fatalln("> Create SCHEMA on database failed:>", e) log.Fatalln("> Create SCHEMA on database failed:>", e)
return e return e
} }
if e := postgres.Initialize_HSTORE(ctx.SQL(), ctx.Schema()); nil != e {
if e := postgres.InitializeHSTORE(ctx.SQL(), ctx.Schema()); nil != e {
log.Fatalln("> Initialize hstore on database failed:>", e) log.Fatalln("> Initialize hstore on database failed:>", e)
return e return e
} }
if e := postgres.Initialize_UUID(ctx.SQL(), ctx.Schema()); nil != e {
if e := postgres.InitializeUUID(ctx.SQL(), ctx.Schema()); nil != e {
log.Fatalln("> Initialize uuid on database failed:>", e) log.Fatalln("> Initialize uuid on database failed:>", e)
return e return e
} }

+ 2
- 2
demo2/models/models.go View File

@ -25,11 +25,11 @@ func Initialize(ctx restlet.TaskContext, params ...interface{}) error {
log.Fatalln("> Create SCHEMA on database failed:>", e) log.Fatalln("> Create SCHEMA on database failed:>", e)
return e return e
} }
if e := postgres.Initialize_HSTORE(ctx.SQL(), ctx.Schema()); nil != e {
if e := postgres.InitializeHSTORE(ctx.SQL(), ctx.Schema()); nil != e {
log.Fatalln("> Initialize hstore on database failed:>", e) log.Fatalln("> Initialize hstore on database failed:>", e)
return e return e
} }
if e := postgres.Initialize_UUID(ctx.SQL(), ctx.Schema()); nil != e {
if e := postgres.InitializeUUID(ctx.SQL(), ctx.Schema()); nil != e {
log.Fatalln("> Initialize uuid on database failed:>", e) log.Fatalln("> Initialize uuid on database failed:>", e)
return e return e
} }

+ 1
- 1
go.mod View File

@ -5,7 +5,7 @@ go 1.12
require ( require (
github.com/Sirupsen/logrus v1.0.3 github.com/Sirupsen/logrus v1.0.3
github.com/archsh/go.uuid v1.1.1 github.com/archsh/go.uuid v1.1.1
github.com/archsh/go.xql v0.4.1
github.com/archsh/go.xql v0.5.1
github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833 github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eclipse/paho.mqtt.golang v1.2.0 github.com/eclipse/paho.mqtt.golang v1.2.0

+ 33
- 1
mqtt/mqtt.go View File

@ -1,6 +1,10 @@
package mqtt package mqtt
import ( import (
"fmt"
"net/url"
"time"
"github.com/eclipse/paho.mqtt.golang" "github.com/eclipse/paho.mqtt.golang"
"cygnux.net/kepler/config" "cygnux.net/kepler/config"
@ -15,6 +19,34 @@ type broker struct {
} }
func SetupBroker(cfg config.Config) (Broker, error) { func SetupBroker(cfg config.Config) (Broker, error) {
client := mqtt.NewClient(mqtt.NewClientOptions())
var opts = mqtt.NewClientOptions()
if svr := cfg.GetString("server"); svr != "" {
if _, e := url.Parse(svr); nil != e {
return nil, e
} else {
opts.AddBroker(svr)
}
} else if svrs := cfg.GetStringSlice("servers"); len(svrs) > 0 {
for _, svr := range svrs {
if _, e := url.Parse(svr); nil != e {
return nil, e
} else {
opts.AddBroker(svr)
}
}
} else {
return nil, fmt.Errorf(" server or servers should be provided")
}
opts.SetClientID(cfg.GetString("clientId"))
if s := cfg.GetString("username"); s != "" {
opts.SetUsername(s)
}
if s := cfg.GetString("password"); s != "" {
opts.SetPassword(s)
}
if d := cfg.GetDuration("keepAlive"); d > time.Second {
opts.SetKeepAlive(d)
}
client := mqtt.NewClient(opts)
return broker{Client: client}, nil return broker{Client: client}, nil
} }

+ 1
- 1
restlet/curd.go View File

@ -416,7 +416,7 @@ func (h DefaultCURDHandler) update(ctx RequestContext, urlParams Parameters, que
for _, c := range h.table.GetColumns() { for _, c := range h.table.GetColumns() {
if _, ok := entityMap[c.FieldName]; ok { if _, ok := entityMap[c.FieldName]; ok {
} else if _, ok := entityMap[c.Jtag]; ok {
} else if _, ok := entityMap[c.JTag]; ok {
} else if _, ok := entityMap[c.ElemName]; ok { } else if _, ok := entityMap[c.ElemName]; ok {

+ 6
- 6
restlet/restlet.go View File

@ -66,10 +66,10 @@ func BuildQueryControl(queries Parameters, table *xql.Table, qmaker QueryMaker,
delete(queries, QCtrlExcludes) delete(queries, QCtrlExcludes)
} }
for k, v := range includeFields { for k, v := range includeFields {
if ! v {
if !v {
continue continue
} }
if c, ok := table.GetColumn(k); ! ok {
if c, ok := table.GetColumn(k); !ok {
return qc, errors.New("Invalid column:" + k) return qc, errors.New("Invalid column:" + k)
} else { } else {
qc.Includes = append(qc.Includes, c.FieldName) qc.Includes = append(qc.Includes, c.FieldName)
@ -97,7 +97,7 @@ func BuildQueryControl(queries Parameters, table *xql.Table, qmaker QueryMaker,
return qc, fmt.Errorf("invalid expression: %s", k) return qc, fmt.Errorf("invalid expression: %s", k)
} }
c, ok := table.GetColumn(keys[0]) c, ok := table.GetColumn(keys[0])
if ! ok {
if !ok {
//return nil, fmt.Errorf("unknow column: %s", keys[0]) //return nil, fmt.Errorf("unknow column: %s", keys[0])
qc.Params[k] = v qc.Params[k] = v
continue continue
@ -160,9 +160,9 @@ func BuildQueryControl(queries Parameters, table *xql.Table, qmaker QueryMaker,
if len(keys) == 3 { if len(keys) == 3 {
switch strings.ToUpper(keys[2]) { switch strings.ToUpper(keys[2]) {
case "AND": case "AND":
f.Condition = xql.CONDITION_AND
f.Condition = xql.ConditionAnd
case "OR": case "OR":
f.Condition = xql.CONDITION_OR
f.Condition = xql.ConditionOr
default: default:
return qc, fmt.Errorf("unknow condition: %s", keys[2]) return qc, fmt.Errorf("unknow condition: %s", keys[2])
} }
@ -239,7 +239,7 @@ func MakeRestletHandler(h RestletHandler, predictor RequestPredictor, ctxProvide
} }
} }
if ! MatchMethod(request.Method, methods) {
if !MatchMethod(request.Method, methods) {
if request.Method == "OPTIONS" { if request.Method == "OPTIONS" {
if methods[0] == "*" { if methods[0] == "*" {
methods = []string{"HEAD", "GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"} methods = []string{"HEAD", "GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}

Loading…
Cancel
Save