This commit is contained in:
MickMake 2022-02-19 15:25:46 +11:00
parent 6d09f20734
commit ef2a04f202
22 changed files with 362 additions and 263 deletions

68
.idea/workspace.xml generated
View File

@ -6,13 +6,26 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="7d634523-07a9-40e1-bec3-1dc036abc5e9" name="Changes" comment=""> <list default="true" id="7d634523-07a9-40e1-bec3-1dc036abc5e9" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/commands.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/commands.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/interface_endpoint.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/interface_endpoint.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/struct_response.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/struct_response.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/utils.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/utils.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/data.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/struct.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerStatistics/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerStatistics/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerStatistics/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerStatistics/struct.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerStatistics/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerStatistics/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsDetailWithPsType/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsDetailWithPsType/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsDetailWithPsType/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsDetailWithPsType/struct.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsDetailWithPsType/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsDetailWithPsType/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsList/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsList/struct.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsList/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPsList/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/auth.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/struct.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/login/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/struct.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/struct.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -73,7 +86,7 @@
<module name="GoSungro" /> <module name="GoSungro" />
<working_directory value="$PROJECT_DIR$" /> <working_directory value="$PROJECT_DIR$" />
<useCustomBuildTags value="true" /> <useCustomBuildTags value="true" />
<parameters value="api get getPowerDevicePointNames" /> <parameters value="api get " />
<kind value="PACKAGE" /> <kind value="PACKAGE" />
<package value="GoSungro" /> <package value="GoSungro" />
<directory value="$PROJECT_DIR$" /> <directory value="$PROJECT_DIR$" />
@ -133,19 +146,9 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>49</line> <line>50</line>
<option name="timeStamp" value="10" /> <option name="timeStamp" value="10" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>25</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>142</line>
<option name="timeStamp" value="13" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_endpoint.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/api/struct_endpoint.go</url>
<line>36</line> <line>36</line>
@ -193,7 +196,7 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/sungro/AppService/struct.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/sungro/AppService/struct.go</url>
<line>621</line> <line>624</line>
<option name="timeStamp" value="236" /> <option name="timeStamp" value="236" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -213,12 +216,12 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/utils.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/api/utils.go</url>
<line>81</line> <line>94</line>
<option name="timeStamp" value="402" /> <option name="timeStamp" value="402" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/utils.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/api/utils.go</url>
<line>83</line> <line>96</line>
<option name="timeStamp" value="405" /> <option name="timeStamp" value="405" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -228,38 +231,33 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/struct.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/struct.go</url>
<line>206</line> <line>219</line>
<option name="timeStamp" value="432" /> <option name="timeStamp" value="432" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>97</line>
<option name="timeStamp" value="445" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>98</line>
<option name="timeStamp" value="446" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>90</line> <line>90</line>
<option name="timeStamp" value="462" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>84</line>
<option name="timeStamp" value="469" /> <option name="timeStamp" value="469" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>104</line> <line>110</line>
<option name="timeStamp" value="481" /> <option name="timeStamp" value="482" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>105</line> <line>103</line>
<option name="timeStamp" value="482" /> <option name="timeStamp" value="487" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/sungro/AppService/getPowerDevicePointNames/struct.go</url>
<line>141</line>
<option name="timeStamp" value="488" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>130</line>
<option name="timeStamp" value="491" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>

View File

@ -2,7 +2,8 @@ package cmd
import ( import (
"GoSungro/Only" "GoSungro/Only"
"GoSungro/iSolarCloud/sungro/AppService/getPowerDevicePointNames" "GoSungro/iSolarCloud/api"
"GoSungro/iSolarCloud/sungro/AppService/login"
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -12,12 +13,12 @@ import (
var cmdApi = &cobra.Command { var cmdApi = &cobra.Command {
Use: "api", Use: "api",
Aliases: []string{}, Aliases: []string{},
Short: fmt.Sprintf("List SunGro areas."), Short: fmt.Sprintf("Interact with the SunGro api."),
Long: fmt.Sprintf("List SunGro areas."), Long: fmt.Sprintf("Interact with the SunGro api."),
Example: PrintExamples("api", "get <endpoint>", "put <endpoint>"), Example: PrintExamples("api", "get <endpoint>", "put <endpoint>"),
DisableFlagParsing: false, DisableFlagParsing: false,
DisableFlagsInUseLine: false, DisableFlagsInUseLine: false,
PreRunE: Cmd.ProcessArgs, // PreRunE: Cmd.ProcessArgs,
Run: cmdApiFunc, Run: cmdApiFunc,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
} }
@ -82,46 +83,69 @@ var cmdApiGet = &cobra.Command {
//goland:noinspection GoUnusedParameter //goland:noinspection GoUnusedParameter
func cmdApiGetFunc(cmd *cobra.Command, args []string) { func cmdApiGetFunc(cmd *cobra.Command, args []string) {
for range Only.Once { for range Only.Once {
hey1 := SunGro.GetEndpoint(args[0]) args = fillArray(2, args)
if hey1.IsError() { if args[1] == "" {
Cmd.Error = hey1.GetError() args[1] = "{}"
}
ep := SunGro.GetEndpoint(args[0])
if ep.IsError() {
Cmd.Error = ep.GetError()
break break
} }
hey1 = hey1.SetRequest(getPowerDevicePointNames.RequestData{ DeviceType: "" }) ep = ep.SetRequestByJson(api.Json(args[1]))
if hey1.IsError() { if ep.IsError() {
fmt.Println(hey1.Help()) fmt.Println(ep.Help())
Cmd.Error = hey1.GetError() Cmd.Error = ep.GetError()
break break
} }
hey1 = hey1.Call() ep = ep.Call()
if hey1.IsError() { if ep.IsError() {
hey1.Help() fmt.Println(ep.Help())
Cmd.Error = hey1.GetError() Cmd.Error = ep.GetError()
break break
} }
fmt.Printf("EndPoint: %v\n", hey1) fmt.Printf("%v", ep.GetData())
fmt.Printf("EndPoint: %v\n", hey1.GetUrl()) }
// fmt.Printf("Request: %s\n", hey1.RequestString()) }
// fmt.Printf("EndPoint: %s\n", hey1.ResponseString())
// hey1 = hey1.Call() // ******************************************************************************** //
// if hey1.IsError() { var cmdApiLogin = &cobra.Command {
// Cmd.Error = hey1.GetError() Use: "login",
// break //Aliases: []string{""},
// } Short: fmt.Sprintf("Login to iSolarCloud"),
// fmt.Printf("resp: %v\n", hey1) Long: fmt.Sprintf("Login to iSolarCloud"),
// Example: PrintExamples("api login", ""),
// DisableFlagParsing: false,
// fmt.Printf("HEY:%v\n", hey1) DisableFlagsInUseLine: false,
// fmt.Printf("HEY:%v\n", hey1.GetError()) PreRunE: Cmd.ProcessArgs,
// fmt.Printf("HEY:%s\n", hey1.GetRequestJson()) Run: cmdApiLoginFunc,
// fmt.Printf("HEY:%s\n", hey1.GetData()) Args: cobra.MinimumNArgs(0),
// if Cmd.Error != nil { }
// break //goland:noinspection GoUnusedParameter
// } func cmdApiLoginFunc(cmd *cobra.Command, args []string) {
for range Only.Once {
Cmd.Error = SunGro.Login(login.SunGroAuth {
AppKey: Cmd.ApiAppKey,
UserAccount: Cmd.ApiUsername,
UserPassword: Cmd.ApiPassword,
TokenFile: Cmd.ApiTokenFile,
Force: true,
})
if Cmd.Error != nil {
break
}
SunGro.Auth.Print()
if SunGro.HasTokenChanged() {
Cmd.ApiLastLogin = SunGro.GetLastLogin()
Cmd.ApiToken = SunGro.GetToken()
Cmd.Error = writeConfig()
}
} }
} }
@ -141,10 +165,11 @@ var cmdApiPut = &cobra.Command {
//goland:noinspection GoUnusedParameter //goland:noinspection GoUnusedParameter
func cmdApiPutFunc(cmd *cobra.Command, args []string) { func cmdApiPutFunc(cmd *cobra.Command, args []string) {
for range Only.Once { for range Only.Once {
args = fillArray(1, args) fmt.Println("Not yet implemented.")
Cmd.Error = SunGro.Init() // args = fillArray(1, args)
if Cmd.Error != nil { // Cmd.Error = SunGro.Init()
break // if Cmd.Error != nil {
} // break
// }
} }
} }

View File

@ -124,7 +124,7 @@ func InitCommands() error {
cmdMqtt.AddCommand(cmdMqttSync) cmdMqtt.AddCommand(cmdMqttSync)
cmdCron.AddCommand(cmdCronRun, cmdCronAdd, cmdCronRemove, cmdCronList) cmdCron.AddCommand(cmdCronRun, cmdCronAdd, cmdCronRemove, cmdCronList)
cmdApi.AddCommand(cmdApiList, cmdApiPut, cmdApiGet) cmdApi.AddCommand(cmdApiList, cmdApiLogin, cmdApiPut, cmdApiGet)
//foo := rootCmd.HelpTemplate() //foo := rootCmd.HelpTemplate()
//foo := rootCmd.UsageTemplate() //foo := rootCmd.UsageTemplate()

View File

@ -124,6 +124,7 @@ func (ca *CommandArgs) ProcessArgs(cmd *cobra.Command, args []string) error {
UserAccount: ca.ApiUsername, UserAccount: ca.ApiUsername,
UserPassword: ca.ApiPassword, UserPassword: ca.ApiPassword,
TokenFile: ca.ApiTokenFile, TokenFile: ca.ApiTokenFile,
Force: false,
}) })
if Cmd.Error != nil { if Cmd.Error != nil {
break break

View File

@ -16,6 +16,7 @@ type EndPoint interface {
MarshalJSON() ([]byte, error) MarshalJSON() ([]byte, error)
SetRequest(ref interface{}) EndPoint // EndPointStruct SetRequest(ref interface{}) EndPoint // EndPointStruct
SetRequestByJson(j Json) EndPoint
RequestRef() interface{} RequestRef() interface{}
GetRequestJson() Json GetRequestJson() Json
IsRequestValid() error IsRequestValid() error

View File

@ -23,11 +23,11 @@ type ResponseCommon struct {
func (req ResponseCommon) IsValid() error { func (req ResponseCommon) IsValid() error {
var err error var err error
for range Only.Once { for range Only.Once {
err = CheckResultMessage(req.ResultMsg) err = req.CheckResultMessage()
if err != nil { if err != nil {
break break
} }
err = CheckResultCode(req.ResultCode) err = req.CheckResultCode()
if err != nil { if err != nil {
break break
} }
@ -43,6 +43,21 @@ func (req ResponseCommon) IsValid() error {
return err return err
} }
func (req ResponseCommon) IsTokenValid() bool {
var ok bool
for range Only.Once {
switch {
case req.ResultMsg == "success":
ok = true
case req.ResultMsg == "er_token_login_invalid":
ok = false
default:
ok = false
}
}
return ok
}
func (req ResponseCommon) String() string { func (req ResponseCommon) String() string {
var ret string var ret string
ret = fmt.Sprintf("ReqSerialNum:\t%s\n", req.ReqSerialNum) ret = fmt.Sprintf("ReqSerialNum:\t%s\n", req.ReqSerialNum)
@ -51,51 +66,47 @@ func (req ResponseCommon) String() string {
return ret return ret
} }
func (req ResponseCommon) CheckResultCode() error {
// ResponseCommon checks
func CheckResultCode(rc string) error {
var err error var err error
for range Only.Once { for range Only.Once {
switch rc { switch req.ResultCode {
case "1": case "1":
err = nil err = nil
case "-1": case "-1":
err = errors.New(fmt.Sprintf("error '%s'", rc)) err = errors.New(fmt.Sprintf("error '%s'", req.ResultCode))
case "010": case "010":
err = errors.New(fmt.Sprintf("error '%s'", rc)) err = errors.New(fmt.Sprintf("error '%s'", req.ResultCode))
case "000": case "000":
err = errors.New(fmt.Sprintf("error '%s'", rc)) err = errors.New(fmt.Sprintf("error '%s'", req.ResultCode))
case "201": case "201":
err = errors.New(fmt.Sprintf("error '%s'", rc)) err = errors.New(fmt.Sprintf("error '%s'", req.ResultCode))
case "E00003": case "E00003":
err = errors.New(fmt.Sprintf("need to login again '%s'", rc)) err = errors.New(fmt.Sprintf("need to login again '%s'", req.ResultCode))
default: default:
err = errors.New(fmt.Sprintf("unknown error '%s'", rc)) err = errors.New(fmt.Sprintf("unknown error '%s'", req.ResultCode))
} }
} }
return err return err
} }
func CheckResultMessage(rc string) error { func (req ResponseCommon) CheckResultMessage() error {
var err error var err error
for range Only.Once { for range Only.Once {
switch { switch {
case rc == "success": case req.ResultMsg == "success":
err = nil err = nil
case rc == "er_invalid_appkey": case req.ResultMsg == "er_invalid_appkey":
err = errors.New(fmt.Sprintf("appkey is incorrect '%s'", rc)) err = errors.New(fmt.Sprintf("appkey is incorrect '%s'", req.ResultMsg))
case rc == "er_token_login_invalid": case req.ResultMsg == "er_token_login_invalid":
err = errors.New(fmt.Sprintf("need to login again '%s'", rc)) err = errors.New(fmt.Sprintf("need to login again '%s'", req.ResultMsg))
case rc == "er_parameter_value_invalid": case req.ResultMsg == "er_parameter_value_invalid":
err = errors.New(fmt.Sprintf("incorrect request data '%s'", rc)) err = errors.New(fmt.Sprintf("incorrect request data '%s'", req.ResultMsg))
case rc == "er_unknown_exception": case req.ResultMsg == "er_unknown_exception":
err = errors.New(fmt.Sprintf("API error '%s'", rc)) err = errors.New(fmt.Sprintf("API error '%s'", req.ResultMsg))
case strings.HasPrefix(rc, "Parameter:"): case strings.HasPrefix(req.ResultMsg, "Parameter:"):
err = errors.New(fmt.Sprintf("incorrect request data '%s'", rc)) err = errors.New(fmt.Sprintf("incorrect request data '%s'", req.ResultMsg))
// case err == nil:
// err = errors.New(fmt.Sprintf("unknown '%s'", rc))
default: default:
err = errors.New(fmt.Sprintf("unknown error '%s'", rc)) err = errors.New(fmt.Sprintf("unknown error '%s'", req.ResultMsg))
} }
} }
return err return err

View File

@ -57,6 +57,19 @@ func GetUrl(u string) *url.URL {
} }
func GetAsJson(r interface{}) Json { func GetAsJson(r interface{}) Json {
var ret Json
for range Only.Once {
j, err := json.Marshal(r)
if err != nil {
ret = Json(fmt.Sprintf("{ \"error\": \"%s\"", err))
break
}
ret = Json(j)
}
return ret
}
func GetAsPrettyJson(r interface{}) Json {
var ret Json var ret Json
for range Only.Once { for range Only.Once {
j, err := json.MarshalIndent(r, "", "\t") j, err := json.MarshalIndent(r, "", "\t")

View File

@ -0,0 +1,13 @@
#!/bin/bash
DEST="$1"
if [ "${DEST}" == "" ]
then
echo "Need a destination endpoint"
exit
fi
mkdir "${DEST}"
perl -pe "s/nullEndPoint/${DEST}/g" nullEndPoint/data.go > "${DEST}/data.go"
perl -pe "s/nullEndPoint/${DEST}/g" nullEndPoint/struct.go > "${DEST}/struct.go"

View File

@ -1,9 +1,8 @@
package getPowerDevicePointNames package getPowerDevicePointNames
import ( import (
"GoSungro/Only"
"GoSungro/iSolarCloud/api/apiReflect" "GoSungro/iSolarCloud/api/apiReflect"
"errors" "fmt"
) )
@ -25,19 +24,23 @@ type RequestData struct {
DeviceType string `json:"device_type" required:"true"` DeviceType string `json:"device_type" required:"true"`
} }
func (rd *RequestData) IsValid() error { func (rd RequestData) IsValid() error {
var err error return apiReflect.VerifyOptionsRequired(rd)
for range Only.Once { }
if rd == nil {
err = errors.New("empty request data") func (rd RequestData) Help() string {
break ret := fmt.Sprintf("device_type can be one of:\n")
} ret += fmt.Sprintf("%s, %s, %s, %s, %s, %s, %s, %s\n",
err = apiReflect.VerifyOptionsRequired(*rd) DeviceType1,
if err != nil { DeviceType3,
break DeviceType4,
} DeviceType5,
} DeviceType7,
return err DeviceType11,
DeviceType14,
DeviceType17,
)
return ret
} }

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string { func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData) ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n" ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.GetRequestJson().String() ret += e.Request.Help()
return ret return ret
} }
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
} }
func (e EndPoint) GetData() api.Json { func (e EndPoint) GetData() api.Json {
return api.GetAsJson(e.Response.ResultData) return api.GetAsPrettyJson(e.Response.ResultData)
} }
func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint { func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
return e return e
} }
func (e EndPoint) SetRequestByJson(j api.Json) api.EndPoint {
for range Only.Once {
e.Error = json.Unmarshal([]byte(j), &e.Request.RequestData)
if e.Error != nil {
break
}
e.Error = e.IsRequestValid()
if e.Error != nil {
break
}
}
return e
}
func (e EndPoint) RequestRef() interface{} { func (e EndPoint) RequestRef() interface{} {
return e.Request return e.Request
} }
@ -171,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
} }
func (e EndPoint) GetResponseJson() api.Json { func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response) return api.GetAsPrettyJson(e.Response)
} }
func (e EndPoint) ResponseRef() interface{} { func (e EndPoint) ResponseRef() interface{} {

View File

@ -1,31 +1,23 @@
package getPowerStatistics package getPowerStatistics
import ( import (
"GoSungro/Only" "GoSungro/iSolarCloud/api/apiReflect"
"GoSungro/iSolarCloud/api" "fmt"
"errors"
) )
const Url = "/v1/powerStationService/getPowerStatistics" const Url = "/v1/powerStationService/getPowerStatistics"
type RequestData struct { type RequestData struct {
PsId string `json:"ps_id"` PsId string `json:"ps_id" required:"true"`
} }
func (rd *RequestData) IsValid() error { func (rd RequestData) IsValid() error {
var err error return apiReflect.VerifyOptionsRequired(rd)
for range Only.Once { }
if rd == nil {
err = errors.New("empty device type") func (rd RequestData) Help() string {
break ret := fmt.Sprintf("ps_id: Can be fetched from getPsList")
} return ret
err = api.CheckString("PsId", rd.PsId)
if err != nil {
err = errors.New("empty device type")
break
}
}
return err
} }

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string { func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData) ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n" ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.GetRequestJson().String() ret += e.Request.Help()
return ret return ret
} }
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
} }
func (e EndPoint) GetData() api.Json { func (e EndPoint) GetData() api.Json {
return api.GetAsJson(e.Response.ResultData) return api.GetAsPrettyJson(e.Response.ResultData)
} }
func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint { func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
return e return e
} }
func (e EndPoint) SetRequestByJson(j api.Json) api.EndPoint {
for range Only.Once {
e.Error = json.Unmarshal([]byte(j), &e.Request.RequestData)
if e.Error != nil {
break
}
e.Error = e.IsRequestValid()
if e.Error != nil {
break
}
}
return e
}
func (e EndPoint) RequestRef() interface{} { func (e EndPoint) RequestRef() interface{} {
return e.Request return e.Request
} }
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
} }
e.Error = req.RequestData.IsValid() e.Error = req.RequestData.IsValid()
if e.Error != nil { if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break break
} }
} }
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
} }
func (e EndPoint) GetResponseJson() api.Json { func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response) return api.GetAsPrettyJson(e.Response)
} }
func (e EndPoint) ResponseRef() interface{} { func (e EndPoint) ResponseRef() interface{} {

View File

@ -1,31 +1,23 @@
package getPsDetailWithPsType package getPsDetailWithPsType
import ( import (
"GoSungro/Only" "GoSungro/iSolarCloud/api/apiReflect"
"GoSungro/iSolarCloud/api" "fmt"
"errors"
) )
const Url = "/v1/powerStationService/getPsDetailWithPsType" const Url = "/v1/powerStationService/getPsDetailWithPsType"
type RequestData struct { type RequestData struct {
PsId string `json:"ps_id"` PsId string `json:"ps_id" required:"true"`
} }
func (rd *RequestData) IsValid() error { func (rd RequestData) IsValid() error {
var err error return apiReflect.VerifyOptionsRequired(rd)
for range Only.Once { }
if rd == nil {
err = errors.New("empty device type") func (rd RequestData) Help() string {
break ret := fmt.Sprintf("")
} return ret
err = api.CheckString("PsId", rd.PsId)
if err != nil {
err = errors.New("empty device type")
break
}
}
return err
} }
@ -182,7 +174,7 @@ type ResultData struct {
} `json:"pv_power_map_virgin"` } `json:"pv_power_map_virgin"`
RobotNumSweepCapacity struct { RobotNumSweepCapacity struct {
Num int64 `json:"num"` Num int64 `json:"num"`
SweepCapacity int64 `json:"sweep_capacity"` SweepCapacity float64 `json:"sweep_capacity"`
} `json:"robot_num_sweep_capacity"` } `json:"robot_num_sweep_capacity"`
SelfConsumptionOffsetReminder int64 `json:"self_consumption_offset_reminder"` SelfConsumptionOffsetReminder int64 `json:"self_consumption_offset_reminder"`
So2ReduceTotal struct { So2ReduceTotal struct {

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string { func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData) ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n" ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.GetRequestJson().String() ret += e.Request.Help()
return ret return ret
} }
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
} }
func (e EndPoint) GetData() api.Json { func (e EndPoint) GetData() api.Json {
return api.GetAsJson(e.Response.ResultData) return api.GetAsPrettyJson(e.Response.ResultData)
} }
func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint { func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
return e return e
} }
func (e EndPoint) SetRequestByJson(j api.Json) api.EndPoint {
for range Only.Once {
e.Error = json.Unmarshal([]byte(j), &e.Request.RequestData)
if e.Error != nil {
break
}
e.Error = e.IsRequestValid()
if e.Error != nil {
break
}
}
return e
}
func (e EndPoint) RequestRef() interface{} { func (e EndPoint) RequestRef() interface{} {
return e.Request return e.Request
} }
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
} }
e.Error = req.RequestData.IsValid() e.Error = req.RequestData.IsValid()
if e.Error != nil { if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break break
} }
} }
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
} }
func (e EndPoint) GetResponseJson() api.Json { func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response) return api.GetAsPrettyJson(e.Response)
} }
func (e EndPoint) ResponseRef() interface{} { func (e EndPoint) ResponseRef() interface{} {

View File

@ -1,8 +1,8 @@
package getPsList package getPsList
import ( import (
"GoSungro/Only" "GoSungro/iSolarCloud/api/apiReflect"
"errors" "fmt"
) )
const Url = "/v1/powerStationService/getPsList" const Url = "/v1/powerStationService/getPsList"
@ -10,20 +10,13 @@ const Url = "/v1/powerStationService/getPsList"
type RequestData struct { type RequestData struct {
} }
func (rd *RequestData) IsValid() error { func (rd RequestData) IsValid() error {
var err error return apiReflect.VerifyOptionsRequired(rd)
for range Only.Once { }
if rd == nil {
err = errors.New("empty device type") func (rd RequestData) Help() string {
break ret := fmt.Sprintf("")
} return ret
// err = api.CheckString("PsId", rd.PsId)
// if err != nil {
// err = errors.New("empty device type")
// break
// }
}
return err
} }
@ -55,7 +48,7 @@ type ResultData struct {
DailyIrradiationVirgin interface{} `json:"daily_irradiation_virgin"` DailyIrradiationVirgin interface{} `json:"daily_irradiation_virgin"`
DesignCapacity string `json:"design_capacity"` DesignCapacity string `json:"design_capacity"`
DesignCapacityUnit string `json:"design_capacity_unit"` DesignCapacityUnit string `json:"design_capacity_unit"`
DesignCapacityVirgin int64 `json:"design_capacity_virgin"` DesignCapacityVirgin float64 `json:"design_capacity_virgin"`
EquivalentHour struct { EquivalentHour struct {
Unit string `json:"unit"` Unit string `json:"unit"`
Value string `json:"value"` Value string `json:"value"`
@ -103,13 +96,13 @@ type ResultData struct {
Unit string `json:"unit"` Unit string `json:"unit"`
Value string `json:"value"` Value string `json:"value"`
} `json:"installed_power_map"` } `json:"installed_power_map"`
InstalledPowerVirgin int64 `json:"installed_power_virgin"` InstalledPowerVirgin float64 `json:"installed_power_virgin"`
InstallerAlarmCount int64 `json:"installer_alarm_count"` InstallerAlarmCount int64 `json:"installer_alarm_count"`
InstallerFaultCount int64 `json:"installer_fault_count"` InstallerFaultCount int64 `json:"installer_fault_count"`
InstallerPsFaultStatus int64 `json:"installer_ps_fault_status"` InstallerPsFaultStatus int64 `json:"installer_ps_fault_status"`
IsBankPs int64 `json:"is_bank_ps"` IsBankPs int64 `json:"is_bank_ps"`
IsTuv int64 `json:"is_tuv"` IsTuv int64 `json:"is_tuv"`
JoinYearInitElec int64 `json:"join_year_init_elec"` JoinYearInitElec float64 `json:"join_year_init_elec"`
Latitude float64 `json:"latitude"` Latitude float64 `json:"latitude"`
Location string `json:"location"` Location string `json:"location"`
Longitude float64 `json:"longitude"` Longitude float64 `json:"longitude"`
@ -133,22 +126,22 @@ type ResultData struct {
P83055 interface{} `json:"p83055"` P83055 interface{} `json:"p83055"`
P83067 interface{} `json:"p83067"` P83067 interface{} `json:"p83067"`
P83070 interface{} `json:"p83070"` P83070 interface{} `json:"p83070"`
P83076 int64 `json:"p83076"` P83076 float64 `json:"p83076"`
P83077 int64 `json:"p83077"` P83077 float64 `json:"p83077"`
P83081 int64 `json:"p83081"` P83081 float64 `json:"p83081"`
P83089 int64 `json:"p83089"` P83089 float64 `json:"p83089"`
P83095 int64 `json:"p83095"` P83095 float64 `json:"p83095"`
P83118 int64 `json:"p83118"` P83118 float64 `json:"p83118"`
P83120 int64 `json:"p83120"` P83120 float64 `json:"p83120"`
P83127 int64 `json:"p83127"` P83127 float64 `json:"p83127"`
ParamCo2 float64 `json:"param_co2"` ParamCo2 float64 `json:"param_co2"`
ParamCoal float64 `json:"param_coal"` ParamCoal float64 `json:"param_coal"`
ParamIncome int64 `json:"param_income"` ParamIncome float64 `json:"param_income"`
ParamMeter float64 `json:"param_meter"` ParamMeter float64 `json:"param_meter"`
ParamNox float64 `json:"param_nox"` ParamNox float64 `json:"param_nox"`
ParamPowder float64 `json:"param_powder"` ParamPowder float64 `json:"param_powder"`
ParamSo2 float64 `json:"param_so2"` ParamSo2 float64 `json:"param_so2"`
ParamTree int64 `json:"param_tree"` ParamTree float64 `json:"param_tree"`
ParamWater float64 `json:"param_water"` ParamWater float64 `json:"param_water"`
PrScale string `json:"pr_scale"` PrScale string `json:"pr_scale"`
Producer interface{} `json:"producer"` Producer interface{} `json:"producer"`
@ -201,9 +194,9 @@ type ResultData struct {
Unit string `json:"unit"` Unit string `json:"unit"`
Value string `json:"value"` Value string `json:"value"`
} `json:"total_income"` } `json:"total_income"`
TotalInitCo2Accelerate int64 `json:"total_init_co2_accelerate"` TotalInitCo2Accelerate float64 `json:"total_init_co2_accelerate"`
TotalInitElec int64 `json:"total_init_elec"` TotalInitElec float64 `json:"total_init_elec"`
TotalInitProfit int64 `json:"total_init_profit"` TotalInitProfit float64 `json:"total_init_profit"`
UseEnergy struct { UseEnergy struct {
Unit string `json:"unit"` Unit string `json:"unit"`
Value string `json:"value"` Value string `json:"value"`

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string { func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData) ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n" ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.GetRequestJson().String() ret += e.Request.Help()
return ret return ret
} }
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
} }
func (e EndPoint) GetData() api.Json { func (e EndPoint) GetData() api.Json {
return api.GetAsJson(e.Response.ResultData) return api.GetAsPrettyJson(e.Response.ResultData)
} }
func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint { func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
return e return e
} }
func (e EndPoint) SetRequestByJson(j api.Json) api.EndPoint {
for range Only.Once {
e.Error = json.Unmarshal([]byte(j), &e.Request.RequestData)
if e.Error != nil {
break
}
e.Error = e.IsRequestValid()
if e.Error != nil {
break
}
}
return e
}
func (e EndPoint) RequestRef() interface{} { func (e EndPoint) RequestRef() interface{} {
return e.Request return e.Request
} }
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
} }
e.Error = req.RequestData.IsValid() e.Error = req.RequestData.IsValid()
if e.Error != nil { if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break break
} }
} }
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
} }
func (e EndPoint) GetResponseJson() api.Json { func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response) return api.GetAsPrettyJson(e.Response)
} }
func (e EndPoint) ResponseRef() interface{} { func (e EndPoint) ResponseRef() interface{} {

View File

@ -25,6 +25,7 @@ type SunGroAuth struct {
UserPassword string UserPassword string
TokenFile string TokenFile string
Token string Token string
Force bool
lastLogin time.Time lastLogin time.Time
newToken bool newToken bool
@ -88,6 +89,10 @@ func (e *EndPoint) Login(auth *SunGroAuth) error {
break break
} }
if auth.Force {
e.Auth.newToken = true
}
if !e.HasTokenExpired() { if !e.HasTokenExpired() {
break break
} }

View File

@ -1,45 +1,24 @@
package login package login
import ( import (
"GoSungro/Only" "GoSungro/iSolarCloud/api/apiReflect"
"GoSungro/iSolarCloud/api" "fmt"
"errors"
) )
const Url = "/v1/userService/login" const Url = "/v1/userService/login"
type RequestData struct { type RequestData struct {
// Appkey string `json:"appkey" required:"true"`
// SysCode string `json:"sys_code" required:"true"`
UserAccount string `json:"user_account" required:"true"` UserAccount string `json:"user_account" required:"true"`
UserPassword string `json:"user_password" required:"true"` UserPassword string `json:"user_password" required:"true"`
} }
func (rd *RequestData) IsValid() error { func (rd RequestData) IsValid() error {
var err error return apiReflect.VerifyOptionsRequired(rd)
for range Only.Once { }
if rd == nil {
err = errors.New("empty device type") func (rd RequestData) Help() string {
break ret := fmt.Sprintf("")
} return ret
// err = api.CheckString("SysCode", rd.SysCode)
// if err != nil {
// break
// }
// err = api.CheckString("Appkey", rd.Appkey)
// if err != nil {
// break
// }
err = api.CheckString("UserAccount", rd.UserAccount)
if err != nil {
break
}
err = api.CheckString("UserPassword", rd.UserPassword)
if err != nil {
break
}
}
return err
} }

View File

@ -82,8 +82,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string { func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData) ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n" ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.GetRequestJson().String() ret += e.Request.Help()
return ret return ret
} }
@ -104,7 +104,7 @@ func (e EndPoint) Call() api.EndPoint {
} }
func (e EndPoint) GetData() api.Json { func (e EndPoint) GetData() api.Json {
return api.GetAsJson(e.Response.ResultData) return api.GetAsPrettyJson(e.Response.ResultData)
} }
func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint { func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
@ -146,6 +146,16 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
return e return e
} }
func (e EndPoint) SetRequestByJson(j api.Json) api.EndPoint {
for range Only.Once {
e.Error = json.Unmarshal([]byte(j), &e.Request.RequestData)
if e.Error != nil {
break
}
}
return e
}
func (e EndPoint) RequestRef() interface{} { func (e EndPoint) RequestRef() interface{} {
return e.Request return e.Request
} }
@ -184,7 +194,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
} }
func (e EndPoint) GetResponseJson() api.Json { func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response) return api.GetAsPrettyJson(e.Response)
} }
func (e EndPoint) ResponseRef() interface{} { func (e EndPoint) ResponseRef() interface{} {

View File

@ -1,8 +1,8 @@
package nullEndPoint package nullEndPoint
import ( import (
"GoSungro/Only" "GoSungro/iSolarCloud/api/apiReflect"
"errors" "fmt"
) )
@ -10,22 +10,16 @@ const Url = ""
type RequestData struct { type RequestData struct {
// DeviceType string `json:"device_type" required:"true"`
} }
func (rd *RequestData) IsValid() error { func (rd RequestData) IsValid() error {
var err error return apiReflect.VerifyOptionsRequired(rd)
for range Only.Once { }
if rd == nil {
err = errors.New("empty device type") func (rd RequestData) Help() string {
break ret := fmt.Sprintf("")
} return ret
// err = api.CheckString("PsId", rd.PsId)
// if err != nil {
// err = errors.New("empty device type")
// break
// }
}
return err
} }

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string { func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData) ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n" ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.GetRequestJson().String() ret += e.Request.Help()
return ret return ret
} }
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
} }
func (e EndPoint) GetData() api.Json { func (e EndPoint) GetData() api.Json {
return api.GetAsJson(e.Response.ResultData) return api.GetAsPrettyJson(e.Response.ResultData)
} }
func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint { func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
return e return e
} }
func (e EndPoint) SetRequestByJson(j api.Json) api.EndPoint {
for range Only.Once {
e.Error = json.Unmarshal([]byte(j), &e.Request.RequestData)
if e.Error != nil {
break
}
e.Error = e.IsRequestValid()
if e.Error != nil {
break
}
}
return e
}
func (e EndPoint) RequestRef() interface{} { func (e EndPoint) RequestRef() interface{} {
return e.Request return e.Request
} }
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
} }
e.Error = req.RequestData.IsValid() e.Error = req.RequestData.IsValid()
if e.Error != nil { if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break break
} }
} }
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
} }
func (e EndPoint) GetResponseJson() api.Json { func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response) return api.GetAsPrettyJson(e.Response)
} }
func (e EndPoint) ResponseRef() interface{} { func (e EndPoint) ResponseRef() interface{} {

View File

@ -3,6 +3,9 @@ package AppService
import ( import (
"GoSungro/iSolarCloud/api" "GoSungro/iSolarCloud/api"
"GoSungro/iSolarCloud/sungro/AppService/getPowerDevicePointNames" "GoSungro/iSolarCloud/sungro/AppService/getPowerDevicePointNames"
"GoSungro/iSolarCloud/sungro/AppService/getPowerStatistics"
"GoSungro/iSolarCloud/sungro/AppService/getPsDetailWithPsType"
"GoSungro/iSolarCloud/sungro/AppService/getPsList"
"GoSungro/iSolarCloud/sungro/AppService/login" "GoSungro/iSolarCloud/sungro/AppService/login"
"GoSungro/iSolarCloud/sungro/AppService/nullEndPoint" "GoSungro/iSolarCloud/sungro/AppService/nullEndPoint"
"fmt" "fmt"
@ -316,7 +319,7 @@ func Init(apiRoot *api.Web) Area {
"getPowerStationPR": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPowerStationPR"} "getPowerStationPR": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPowerStationPR"}
"getPowerStationTableDataSql": nullEndPoint.Init(apiRoot), // "/v1/devService/getPowerStationTableDataSql"} "getPowerStationTableDataSql": nullEndPoint.Init(apiRoot), // "/v1/devService/getPowerStationTableDataSql"}
"getPowerStationTableDataSqlCount": nullEndPoint.Init(apiRoot), // "/v1/devService/getPowerStationTableDataSqlCount"} "getPowerStationTableDataSqlCount": nullEndPoint.Init(apiRoot), // "/v1/devService/getPowerStationTableDataSqlCount"}
"getPowerStatistics": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPowerStatistics"} api.GetName(getPowerStatistics.EndPoint{}): getPowerStatistics.Init(apiRoot),
"getPowerTrendDayData": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPowerTrendDayData"} "getPowerTrendDayData": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPowerTrendDayData"}
"getPrivateCloudValidityPeriod": nullEndPoint.Init(apiRoot), // "/v1/commonService/getPrivateCloudValidityPeriod"} "getPrivateCloudValidityPeriod": nullEndPoint.Init(apiRoot), // "/v1/commonService/getPrivateCloudValidityPeriod"}
"getProvInfoListByNationCode": nullEndPoint.Init(apiRoot), // "/v1/commonService/getProvInfoListByNationCode"} "getProvInfoListByNationCode": nullEndPoint.Init(apiRoot), // "/v1/commonService/getProvInfoListByNationCode"}
@ -326,11 +329,11 @@ func Init(apiRoot *api.Web) Area {
"getPsDetail": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetail"} "getPsDetail": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetail"}
"getPsDetailByUserTokens": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetailByUserTokens"} "getPsDetailByUserTokens": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetailByUserTokens"}
"getPsDetailForSinglePage": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetailForSinglePage"} "getPsDetailForSinglePage": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetailForSinglePage"}
"getPsDetailWithPsType": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetailWithPsType"} api.GetName(getPsDetailWithPsType.EndPoint{}): getPsDetailWithPsType.Init(apiRoot),
"getPsHealthState": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsHealthState"} "getPsHealthState": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsHealthState"}
"getPsInstallerByPsId": nullEndPoint.Init(apiRoot), // "/v1/orgService/getPsInstallerByPsId"} "getPsInstallerByPsId": nullEndPoint.Init(apiRoot), // "/v1/orgService/getPsInstallerByPsId"}
"getPsInstallerOrgInfoByPsId": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsInstallerOrgInfoByPsId"} "getPsInstallerOrgInfoByPsId": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsInstallerOrgInfoByPsId"}
"getPsList": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsList"} api.GetName(getPsList.EndPoint{}): getPsList.Init(apiRoot),
"getPsListByName": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListByName"} "getPsListByName": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListByName"}
"getPsListForPsDataByPsId": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListForPsDataByPsId"} "getPsListForPsDataByPsId": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListForPsDataByPsId"}
"getPsListStaticData": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListStaticData"} "getPsListStaticData": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListStaticData"}