Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MickMake committed Feb 18, 2022
1 parent f229330 commit 6d09f20
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 81 deletions.
42 changes: 2 additions & 40 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (rd *RequestData) IsValid() error {
var err error
for range Only.Once {
if rd == nil {
err = errors.New("empty device type")
err = errors.New("empty request data")
break
}
err = apiReflect.VerifyOptionsRequired(*rd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,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
}
}
Expand Down
16 changes: 12 additions & 4 deletions iSolarCloud/sungro/AppService/getPowerStatistics/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"
)


Expand Down Expand Up @@ -35,7 +34,7 @@ func Init(apiRoot *api.Web) EndPoint {
ApiRoot: apiRoot,
Area: api.GetArea(EndPoint{}),
Name: api.GetName(EndPoint{}),
Url: api.GetUrl(Url),
Url: api.SetUrl(Url),
Request: Request{},
Response: Response{},
Error: nil,
Expand Down Expand Up @@ -68,6 +67,13 @@ func Assert(e api.EndPoint) EndPoint {
// ****************************************
// Methods defined by api.EndPoint interface type

func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
return ret
}

func (e EndPoint) GetArea() api.AreaName {
return e.Area
}
Expand All @@ -94,7 +100,7 @@ func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
}

func (e EndPoint) GetError() error {
return e.Error
return e.EndPointStruct.Error
}

func (e EndPoint) IsError() bool {
Expand All @@ -113,6 +119,7 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {

if apiReflect.GetType(ref) == "RequestData" {
e.Request.RequestData = ref.(RequestData)
e.Error = e.IsRequestValid()
break
}

Expand All @@ -131,7 +138,7 @@ func (e EndPoint) RequestRef() interface{} {
}

func (e EndPoint) GetRequestJson() api.Json {
return api.GetAsJson(e.Request)
return api.GetAsJson(e.Request.RequestData)
}

func (e EndPoint) IsRequestValid() error {
Expand All @@ -144,6 +151,7 @@ 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
}
}
Expand Down
17 changes: 13 additions & 4 deletions iSolarCloud/sungro/AppService/getPsDetailWithPsType/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"
)


Expand Down Expand Up @@ -35,7 +34,7 @@ func Init(apiRoot *api.Web) EndPoint {
ApiRoot: apiRoot,
Area: api.GetArea(EndPoint{}),
Name: api.GetName(EndPoint{}),
Url: api.GetUrl(Url),
Url: api.SetUrl(Url),
Request: Request{},
Response: Response{},
Error: nil,
Expand Down Expand Up @@ -68,6 +67,13 @@ func Assert(e api.EndPoint) EndPoint {
// ****************************************
// Methods defined by api.EndPoint interface type

func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
return ret
}

func (e EndPoint) GetArea() api.AreaName {
return e.Area
}
Expand All @@ -90,10 +96,11 @@ func (e EndPoint) GetData() api.Json {

func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
e.EndPointStruct.Error = errors.New(fmt.Sprintf(format, a...))
return e
}

func (e EndPoint) GetError() error {
return e.Error
return e.EndPointStruct.Error
}

func (e EndPoint) IsError() bool {
Expand All @@ -112,6 +119,7 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {

if apiReflect.GetType(ref) == "RequestData" {
e.Request.RequestData = ref.(RequestData)
e.Error = e.IsRequestValid()
break
}

Expand All @@ -130,7 +138,7 @@ func (e EndPoint) RequestRef() interface{} {
}

func (e EndPoint) GetRequestJson() api.Json {
return api.GetAsJson(e.Request)
return api.GetAsJson(e.Request.RequestData)
}

func (e EndPoint) IsRequestValid() error {
Expand All @@ -143,6 +151,7 @@ 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
}
}
Expand Down
17 changes: 13 additions & 4 deletions iSolarCloud/sungro/AppService/getPsList/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"
)


var _ api.EndPoint = (*EndPoint)(nil)

type EndPoint struct {
Expand All @@ -34,7 +34,7 @@ func Init(apiRoot *api.Web) EndPoint {
ApiRoot: apiRoot,
Area: api.GetArea(EndPoint{}),
Name: api.GetName(EndPoint{}),
Url: api.GetUrl(Url),
Url: api.SetUrl(Url),
Request: Request{},
Response: Response{},
Error: nil,
Expand Down Expand Up @@ -67,6 +67,13 @@ func Assert(e api.EndPoint) EndPoint {
// ****************************************
// Methods defined by api.EndPoint interface type

func (e EndPoint) Help() string {
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
return ret
}

func (e EndPoint) GetArea() api.AreaName {
return e.Area
}
Expand All @@ -93,7 +100,7 @@ func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
}

func (e EndPoint) GetError() error {
return e.Error
return e.EndPointStruct.Error
}

func (e EndPoint) IsError() bool {
Expand All @@ -112,6 +119,7 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {

if apiReflect.GetType(ref) == "RequestData" {
e.Request.RequestData = ref.(RequestData)
e.Error = e.IsRequestValid()
break
}

Expand All @@ -130,7 +138,7 @@ func (e EndPoint) RequestRef() interface{} {
}

func (e EndPoint) GetRequestJson() api.Json {
return api.GetAsJson(e.Request)
return api.GetAsJson(e.Request.RequestData)
}

func (e EndPoint) IsRequestValid() error {
Expand All @@ -143,6 +151,7 @@ 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
}
}
Expand Down
50 changes: 26 additions & 24 deletions iSolarCloud/sungro/AppService/login/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ var _ api.EndPoint = (*EndPoint)(nil)

type EndPoint struct {
api.EndPointStruct
Auth *SunGroAuth
Request Request
Response Response
Auth *SunGroAuth
}

type Request struct {
api.RequestCommon // login is special as it doesn't have the usual fields.
api.RequestCommon
RequestData
}

Expand All @@ -31,12 +31,10 @@ type Response struct {
ResultData ResultData `json:"result_data"`
}


func Init(apiRoot *api.Web) EndPoint {
return EndPoint {
EndPointStruct: api.EndPointStruct {
ApiRoot: apiRoot,

Area: api.GetArea(EndPoint{}),
Name: api.GetName(EndPoint{}),
Url: api.SetUrl(Url),
Expand Down Expand Up @@ -83,7 +81,10 @@ func Assert(e api.EndPoint) EndPoint {
// Methods defined by api.EndPoint interface type

func (e EndPoint) Help() string {
return apiReflect.HelpOptions(e.Request.RequestData)
ret := apiReflect.HelpOptions(e.Request.RequestData)
ret += "JSON request:\n"
ret += e.GetRequestJson().String()
return ret
}

func (e EndPoint) GetArea() api.AreaName {
Expand Down Expand Up @@ -112,7 +113,7 @@ func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint {
}

func (e EndPoint) GetError() error {
return e.Error
return e.EndPointStruct.Error
}

func (e EndPoint) IsError() bool {
Expand All @@ -131,6 +132,7 @@ func (e EndPoint) SetRequest(ref interface{}) api.EndPoint {

if apiReflect.GetType(ref) == "RequestData" {
e.Request.RequestData = ref.(RequestData)
e.Error = e.IsRequestValid()
break
}

Expand All @@ -149,7 +151,7 @@ func (e EndPoint) RequestRef() interface{} {
}

func (e EndPoint) GetRequestJson() api.Json {
return api.GetAsJson(e.Request)
return api.GetAsJson(e.Request.RequestData)
}

func (e EndPoint) IsRequestValid() error {
Expand Down Expand Up @@ -214,21 +216,21 @@ func (e EndPoint) ResponseString() string {
}

func (e EndPoint) MarshalJSON() ([]byte, error) {
// return api.MarshalJSON(e)

return json.Marshal(&struct {
Area string `json:"area"`
EndPoint string `json:"endpoint"`
Host string `json:"api_host"`
Url string `json:"endpoint_url"`
Request interface{} `json:"request"`
Response interface{} `json:"response"`
}{
Area: string(e.Area),
EndPoint: string(e.Name),
Host: e.ApiRoot.Url.String(),
Url: e.Url.String(),
Request: e.Request,
Response: e.Response,
})
return api.MarshalJSON(e)

// return json.Marshal(&struct {
// Area string `json:"area"`
// EndPoint string `json:"endpoint"`
// Host string `json:"api_host"`
// Url string `json:"endpoint_url"`
// Request interface{} `json:"request"`
// Response interface{} `json:"response"`
// }{
// Area: string(e.Area),
// EndPoint: string(e.Name),
// Host: e.ApiRoot.Url.String(),
// Url: e.Url.String(),
// Request: e.Request,
// Response: e.Response,
// })
}
Loading

0 comments on commit 6d09f20

Please sign in to comment.