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">
<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$/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/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/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/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/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/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/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/sungro/AppService/struct.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -73,7 +86,7 @@
<module name="GoSungro" />
<working_directory value="$PROJECT_DIR$" />
<useCustomBuildTags value="true" />
<parameters value="api get getPowerDevicePointNames" />
<parameters value="api get " />
<kind value="PACKAGE" />
<package value="GoSungro" />
<directory value="$PROJECT_DIR$" />
@ -133,19 +146,9 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>49</line>
<line>50</line>
<option name="timeStamp" value="10" />
</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">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_endpoint.go</url>
<line>36</line>
@ -193,7 +196,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/sungro/AppService/struct.go</url>
<line>621</line>
<line>624</line>
<option name="timeStamp" value="236" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -213,12 +216,12 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/utils.go</url>
<line>81</line>
<line>94</line>
<option name="timeStamp" value="402" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/utils.go</url>
<line>83</line>
<line>96</line>
<option name="timeStamp" value="405" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -228,38 +231,33 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/sungro/AppService/nullEndPoint/struct.go</url>
<line>206</line>
<line>219</line>
<option name="timeStamp" value="432" />
</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">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>104</line>
<option name="timeStamp" value="481" />
<line>110</line>
<option name="timeStamp" value="482" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>105</line>
<option name="timeStamp" value="482" />
<line>103</line>
<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>
</breakpoints>
</breakpoint-manager>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.Request.Help()
return ret
}
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
}
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 {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
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{} {
return e.Request
}
@ -171,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
}
func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response)
return api.GetAsPrettyJson(e.Response)
}
func (e EndPoint) ResponseRef() interface{} {

View File

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

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.Request.Help()
return ret
}
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
}
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 {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
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{} {
return e.Request
}
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
}
e.Error = req.RequestData.IsValid()
if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break
}
}
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
}
func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response)
return api.GetAsPrettyJson(e.Response)
}
func (e EndPoint) ResponseRef() interface{} {

View File

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

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.Request.Help()
return ret
}
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
}
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 {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
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{} {
return e.Request
}
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
}
e.Error = req.RequestData.IsValid()
if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break
}
}
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
}
func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response)
return api.GetAsPrettyJson(e.Response)
}
func (e EndPoint) ResponseRef() interface{} {

View File

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

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.Request.Help()
return ret
}
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
}
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 {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
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{} {
return e.Request
}
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
}
e.Error = req.RequestData.IsValid()
if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break
}
}
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
}
func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response)
return api.GetAsPrettyJson(e.Response)
}
func (e EndPoint) ResponseRef() interface{} {

View File

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

View File

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

View File

@ -82,8 +82,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.Request.Help()
return ret
}
@ -104,7 +104,7 @@ func (e EndPoint) Call() api.EndPoint {
}
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 {
@ -146,6 +146,16 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
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{} {
return e.Request
}
@ -184,7 +194,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
}
func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response)
return api.GetAsPrettyJson(e.Response)
}
func (e EndPoint) ResponseRef() interface{} {

View File

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

View File

@ -69,8 +69,8 @@ func Assert(e api.EndPoint) EndPoint {
func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson())
ret += e.Request.Help()
return ret
}
@ -91,7 +91,7 @@ func (e EndPoint) Call() api.EndPoint {
}
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 {
@ -133,6 +133,20 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {
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{} {
return e.Request
}
@ -151,7 +165,6 @@ func (e EndPoint) IsRequestValid() error {
}
e.Error = req.RequestData.IsValid()
if e.Error != nil {
// e.Error = errors.New(fmt.Sprintf("%s\n%s\n", e.Error, e.Help()))
break
}
}
@ -172,7 +185,7 @@ func (e EndPoint) SetResponse(ref []byte) api.EndPoint {
}
func (e EndPoint) GetResponseJson() api.Json {
return api.GetAsJson(e.Response)
return api.GetAsPrettyJson(e.Response)
}
func (e EndPoint) ResponseRef() interface{} {

View File

@ -3,6 +3,9 @@ package AppService
import (
"GoSungro/iSolarCloud/api"
"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/nullEndPoint"
"fmt"
@ -316,7 +319,7 @@ func Init(apiRoot *api.Web) Area {
"getPowerStationPR": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPowerStationPR"}
"getPowerStationTableDataSql": nullEndPoint.Init(apiRoot), // "/v1/devService/getPowerStationTableDataSql"}
"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"}
"getPrivateCloudValidityPeriod": nullEndPoint.Init(apiRoot), // "/v1/commonService/getPrivateCloudValidityPeriod"}
"getProvInfoListByNationCode": nullEndPoint.Init(apiRoot), // "/v1/commonService/getProvInfoListByNationCode"}
@ -326,11 +329,11 @@ func Init(apiRoot *api.Web) Area {
"getPsDetail": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetail"}
"getPsDetailByUserTokens": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsDetailByUserTokens"}
"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"}
"getPsInstallerByPsId": nullEndPoint.Init(apiRoot), // "/v1/orgService/getPsInstallerByPsId"}
"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"}
"getPsListForPsDataByPsId": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListForPsDataByPsId"}
"getPsListStaticData": nullEndPoint.Init(apiRoot), // "/v1/powerStationService/getPsListStaticData"}