mirror of
https://github.com/kerberos-io/onvif.git
synced 2025-10-07 00:33:37 +08:00
xml processing
This commit is contained in:
77
api/api.go
77
api/api.go
@@ -1,37 +1,66 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"github.com/yakovlevdmv/goonvif"
|
||||
"github.com/yakovlevdmv/goonvif/Device"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func RunApi () {
|
||||
router := gin.Default()
|
||||
//func RunApi () {
|
||||
// router := gin.Default()
|
||||
//
|
||||
// router.POST("/:service/:method", func(c *gin.Context) {
|
||||
// serviceName := c.Param("service")
|
||||
// methodName := c.Param("method")
|
||||
// message := callNecessaryMethod(&serviceName, &methodName, "192.168.13.12")
|
||||
// c.XML(http.StatusOK, message)
|
||||
// })
|
||||
// router.Run()
|
||||
//}
|
||||
|
||||
device := goonvif.NewDevice()
|
||||
data, err := device.CallMethod("http://192.168.13.12/onvif/device_service", Device.GetCapabilities{Category:"All"})
|
||||
//_=data
|
||||
func soapHandling(tp interface{}, tags* map[string]string) {
|
||||
ifaceValue := reflect.ValueOf(tp).Elem()
|
||||
typeOfStruct := ifaceValue.Type()
|
||||
if ifaceValue.Kind() != reflect.Struct {
|
||||
return
|
||||
}
|
||||
for i := 0; i < ifaceValue.NumField(); i++ {
|
||||
field := ifaceValue.Field(i)
|
||||
tg, err := typeOfStruct.FieldByName(typeOfStruct.Field(i).Name)
|
||||
if err == false {
|
||||
fmt.Println(err)
|
||||
}
|
||||
(*tags)[typeOfStruct.Field(i).Name] = string(tg.Tag)
|
||||
|
||||
subStruct := reflect.New(reflect.TypeOf( field.Interface() ))
|
||||
soapHandling(subStruct.Interface(), tags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func callNecessaryMethod(serviceName* string, methodName* string, deviceXaddr* string) *string {
|
||||
switch *serviceName {
|
||||
case "Device", "device":
|
||||
return callDeviceMethods(methodName, deviceXaddr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func callDeviceMethods(methodName* string, deviceXaddr* string) *string {
|
||||
switch *methodName {
|
||||
case "GetCapabilities":
|
||||
return GetCapabilities(deviceXaddr)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetCapabilities(deviceXaddr* string) *string {
|
||||
device := goonvif.NewDevice(*deviceXaddr)
|
||||
data, err := device.CallMethod(Device.GetCapabilities{Category:"All"})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
router.GET("/:dima", func(c *gin.Context) {
|
||||
//name := c.Param("name")
|
||||
c.XML(http.StatusOK, data)
|
||||
})
|
||||
router.Run()
|
||||
}
|
||||
|
||||
func callNecessaryMethod(serviceName, methodName string) {
|
||||
switch serviceName {
|
||||
case "Device", "device":
|
||||
callDeviceMethonds(methodName)
|
||||
}
|
||||
}
|
||||
|
||||
func callDeviceMethonds(methodName string) {
|
||||
|
||||
return &data
|
||||
}
|
Reference in New Issue
Block a user