mirror of
https://github.com/luscis/openlan.git
synced 2025-10-05 16:47:11 +08:00
35 lines
681 B
Go
Executable File
35 lines
681 B
Go
Executable File
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/luscis/openlan/pkg/libol"
|
|
"github.com/luscis/openlan/pkg/schema"
|
|
)
|
|
|
|
type Log struct {
|
|
}
|
|
|
|
func (l Log) Router(router *mux.Router) {
|
|
router.HandleFunc("/api/log", l.List).Methods("GET")
|
|
router.HandleFunc("/api/log", l.Add).Methods("POST")
|
|
}
|
|
|
|
func (l Log) List(w http.ResponseWriter, r *http.Request) {
|
|
log := schema.NewLogSchema()
|
|
ResponseJson(w, log)
|
|
}
|
|
|
|
func (l Log) Add(w http.ResponseWriter, r *http.Request) {
|
|
log := &schema.Log{}
|
|
if err := GetData(r, log); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
libol.SetLevel(log.Level)
|
|
|
|
ResponseMsg(w, 0, "")
|
|
}
|