WIP: JSONRPC server refactoring
This commit is contained in:
32
cmd/server/jsonrpc/scan_wifi.go
Normal file
32
cmd/server/jsonrpc/scan_wifi.go
Normal file
@ -0,0 +1,32 @@
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/Cadoles/owrt"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
type ScanWifiArgs struct{}
|
||||
|
||||
type ScanWifiReply struct {
|
||||
AccessPoints []*owrt.WifiCell
|
||||
}
|
||||
|
||||
// ScanWifi starts a WiFi scan and returns available access points
|
||||
func (o *OrionService) ScanWifi(r *http.Request, args *ScanWifiArgs, reply *ScanWifiReply) error {
|
||||
|
||||
o.UCI.LoadWirelessConf()
|
||||
ifaces := o.UCI.GetWifiIfaces()
|
||||
|
||||
reply.AccessPoints = make([]*owrt.WifiCell, 0)
|
||||
|
||||
for _, iface := range ifaces {
|
||||
scanner := owrt.NewWifiScanner(iface.Name)
|
||||
cells := scanner.Scan()
|
||||
spew.Dump(iface, cells)
|
||||
reply.AccessPoints = append(reply.AccessPoints, cells...)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
"forge.cadoles.com/wpetit/goweb/service"
|
||||
"github.com/gorilla/rpc"
|
||||
|
||||
"forge.cadoles.com/wpetit/goweb/service"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -10,17 +11,14 @@ const ServiceName service.Name = "jsonrpc"
|
||||
|
||||
// From retrieves the JSONRPC service in the given container or panic
|
||||
func From(container *service.Container) (*rpc.Server, error) {
|
||||
|
||||
service, err := container.Service(ServiceName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
|
||||
}
|
||||
|
||||
jsonRPCService, ok := service.(*rpc.Server)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
|
||||
}
|
||||
|
||||
return jsonRPCService, nil
|
||||
}
|
||||
|
||||
|
11
cmd/server/jsonrpc/testdata/test_rest.rest
vendored
11
cmd/server/jsonrpc/testdata/test_rest.rest
vendored
@ -1,6 +1,17 @@
|
||||
POST http://192.168.100.1:8888/rpc HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"id": 0,
|
||||
"method": "Orion.OwrtListWifiDevices",
|
||||
"params": []
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST http://192.168.100.1:8888/rpc HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"method": "Orion.OwrtCreateWifiInterface",
|
||||
|
Reference in New Issue
Block a user