add api example
This commit is contained in:
parent
821f703dae
commit
a7e315d573
|
@ -1,12 +1,95 @@
|
|||
package index_management
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"infini.sh/framework/core/api"
|
||||
httprouter "infini.sh/framework/core/api/router"
|
||||
"infini.sh/framework/core/orm"
|
||||
"infini.sh/framework/core/util"
|
||||
model2 "infini.sh/search-center/model"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func API1(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
|
||||
type APIHandler struct {
|
||||
api.Handler
|
||||
}
|
||||
|
||||
|
||||
func (handler APIHandler)CreateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
//id := ps.ByName("id")
|
||||
dict:=model2.Dict{}
|
||||
dict.ID = util.GetUUID()
|
||||
|
||||
err := orm.Save(dict)
|
||||
if err!=nil{
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (handler APIHandler) DeleteDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
id := ps.ByName("id")
|
||||
dict:=model2.Dict{}
|
||||
dict.ID = id
|
||||
|
||||
|
||||
err := orm.Delete(dict)
|
||||
if err!=nil{
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (handler APIHandler) DeleteDictItemAction2(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
|
||||
field:=handler.GetParameterOrDefault(req,"help","help message")
|
||||
fmt.Println(field)
|
||||
|
||||
json,err:=handler.GetJSON(req)
|
||||
if err!=nil{
|
||||
handler.Error(w,err)
|
||||
return
|
||||
}
|
||||
|
||||
id,err:=json.String("id")
|
||||
if err!=nil{
|
||||
handler.Error(w,err)
|
||||
return
|
||||
}
|
||||
dict:=model2.Dict{}
|
||||
dict.ID = id
|
||||
|
||||
|
||||
err = orm.Delete(dict)
|
||||
if err!=nil{
|
||||
handler.Error(w,err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TaskAction handle task creation and return task list which support parameter: `from`, `size` and `host`, eg:
|
||||
//curl -XGET http://127.0.0.1:8001/task?from=100&size=10&host=elasticsearch.cn
|
||||
func (handler APIHandler) TaskAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
|
||||
//fr := handler.GetParameter(req, "from")
|
||||
//si := handler.GetParameter(req, "size")
|
||||
//host := handler.GetParameter(req, "host")
|
||||
//status := handler.GetIntOrDefault(req, "status", -1)
|
||||
//
|
||||
//from, err := strconv.Atoi(fr)
|
||||
//if err != nil {
|
||||
// from = 0
|
||||
//}
|
||||
//size, err := strconv.Atoi(si)
|
||||
//if err != nil {
|
||||
// size = 10
|
||||
//}
|
||||
//
|
||||
//orm.Search()
|
||||
//total, tasks, err := model.GetTaskList(from, size, host, status)
|
||||
//if err != nil {
|
||||
// handler.Error(w, err)
|
||||
//} else {
|
||||
// handler.WriteJSONListResult(w, total, tasks, http.StatusOK)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,5 +7,10 @@ import (
|
|||
)
|
||||
|
||||
func Init() {
|
||||
ui.HandleUIMethod(api.POST, "/api/get_indices",index_management.API1)
|
||||
handler:=index_management.APIHandler{}
|
||||
//ui.HandleUIMethod(api.POST, "/api/get_indices",index_management.API1)
|
||||
ui.HandleUIMethod(api.POST, "/api/dict/_create",handler.CreateDictItemAction)
|
||||
//ui.HandleUIMethod(api.GET, "/api/dict/:id",handler.GetDictItemAction)
|
||||
ui.HandleUIMethod(api.DELETE, "/api/dict/:id",handler.DeleteDictItemAction)
|
||||
ui.HandleUIMethod(api.DELETE, "/api/dict/",handler.DeleteDictItemAction2)
|
||||
}
|
4
main.go
4
main.go
|
@ -6,8 +6,10 @@ import (
|
|||
"infini.sh/framework"
|
||||
"infini.sh/framework/core/env"
|
||||
"infini.sh/framework/core/module"
|
||||
"infini.sh/framework/core/orm"
|
||||
"infini.sh/framework/modules"
|
||||
"infini.sh/search-center/config"
|
||||
"infini.sh/search-center/model"
|
||||
)
|
||||
|
||||
var appConfig *config.AppConfig
|
||||
|
@ -66,7 +68,7 @@ func main() {
|
|||
module.Start()
|
||||
|
||||
}, func() {
|
||||
|
||||
orm.RegisterSchema(model.Dict{})
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package model
|
||||
|
||||
type Dict struct {
|
||||
ID string `json:"id" elastic_meta:"_id"`
|
||||
Url string `json:"title,omitempty"`
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
elasticsearch:
|
||||
- name: default
|
||||
enabled: true
|
||||
endpoint: http://localhost:9200
|
||||
endpoint: https://192.168.3.98:9200
|
||||
index_prefix: infini-
|
||||
basic_auth:
|
||||
username: elastic
|
||||
password: 13A1EcwWs1He6w3BXHuJ
|
||||
password: ZBdkVQUUdF1Sir4X4BGB
|
||||
|
||||
web:
|
||||
enabled: true
|
||||
|
@ -24,7 +24,7 @@ modules:
|
|||
enabled: true
|
||||
indexer_enabled: false
|
||||
store_enabled: false
|
||||
orm_enabled: false
|
||||
orm_enabled: true
|
||||
- name: web
|
||||
enabled: true
|
||||
network:
|
||||
|
@ -35,3 +35,19 @@ search-center:
|
|||
ui_path: .public
|
||||
ui_vfs: true
|
||||
ui_local: true
|
||||
|
||||
|
||||
|
||||
queue:
|
||||
min_msg_size: 1
|
||||
max_msg_size: 5000000000
|
||||
max_bytes_per_file: 53687091200
|
||||
sync_every_records: 100000 # sync by records count
|
||||
sync_timeout_in_ms: 10000 # sync by time in million seconds
|
||||
read_chan_buffer: 0
|
||||
|
||||
statsd:
|
||||
enabled: false
|
||||
host: 127.0.0.1
|
||||
port: 8125
|
||||
namespace: gateway.
|
||||
|
|
Loading…
Reference in New Issue