diff options
| author | Shulhan <ms@kilabit.info> | 2021-09-29 00:37:57 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-09-29 00:37:57 +0700 |
| commit | f9c01618f3a59c257ee601d3cf4de5b0e3d73675 (patch) | |
| tree | c8fdb27f6325d2e4092778d4e69b1cd6df86391b /http_server.go | |
| parent | afb02f3df1f440c16e5a3c4fc1b117eac6d029dc (diff) | |
| download | gorankusu-f9c01618f3a59c257ee601d3cf4de5b0e3d73675.tar.xz | |
all: implement WebSocket notification when attack finished
When the attack finished, the WebSocket server will broadcast the
result to all clients as message "/_trunks/api/attack/result".
Diffstat (limited to 'http_server.go')
| -rw-r--r-- | http_server.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/http_server.go b/http_server.go index fb437ac..e83e9a3 100644 --- a/http_server.go +++ b/http_server.go @@ -22,15 +22,15 @@ var ( ResponseType: libhttp.ResponseTypeJSON, } - apiTargetAttackResultDelete = &libhttp.Endpoint{ + apiAttackResultDelete = &libhttp.Endpoint{ Method: libhttp.RequestMethodDelete, - Path: "/_trunks/api/target/attack/result", + Path: apiAttackResult, RequestType: libhttp.RequestTypeJSON, ResponseType: libhttp.ResponseTypeJSON, } - apiTargetAttackResultGet = &libhttp.Endpoint{ + apiAttackResultGet = &libhttp.Endpoint{ Method: libhttp.RequestMethodGet, - Path: "/_trunks/api/target/attack/result", + Path: apiAttackResult, RequestType: libhttp.RequestTypeQuery, ResponseType: libhttp.ResponseTypeJSON, } @@ -82,13 +82,13 @@ func (trunks *Trunks) initHttpServer(isDevelopment bool) (err error) { return fmt.Errorf("%s: %w", logp, err) } - apiTargetAttackResultDelete.Call = trunks.apiTargetAttackResultDelete - err = trunks.Httpd.RegisterEndpoint(apiTargetAttackResultDelete) + apiAttackResultDelete.Call = trunks.apiAttackResultDelete + err = trunks.Httpd.RegisterEndpoint(apiAttackResultDelete) if err != nil { return fmt.Errorf("%s: %w", logp, err) } - apiTargetAttackResultGet.Call = trunks.apiTargetAttackResultGet - err = trunks.Httpd.RegisterEndpoint(apiTargetAttackResultGet) + apiAttackResultGet.Call = trunks.apiAttackResultGet + err = trunks.Httpd.RegisterEndpoint(apiAttackResultGet) if err != nil { return fmt.Errorf("%s: %w", logp, err) } @@ -123,7 +123,7 @@ func (trunks *Trunks) apiEnvironmentGet(epr *libhttp.EndpointRequest) (resbody [ return json.Marshal(&res) } -func (trunks *Trunks) apiTargetAttackResultDelete(epr *libhttp.EndpointRequest) (resbody []byte, err error) { +func (trunks *Trunks) apiAttackResultDelete(epr *libhttp.EndpointRequest) (resbody []byte, err error) { name := epr.HttpRequest.Form.Get(paramNameName) if len(name) == 0 { return nil, errInvalidParameter(paramNameName, name) @@ -144,7 +144,7 @@ func (trunks *Trunks) apiTargetAttackResultDelete(epr *libhttp.EndpointRequest) return json.Marshal(&res) } -func (trunks *Trunks) apiTargetAttackResultGet(epr *libhttp.EndpointRequest) (resbody []byte, err error) { +func (trunks *Trunks) apiAttackResultGet(epr *libhttp.EndpointRequest) (resbody []byte, err error) { name := epr.HttpRequest.Form.Get(paramNameName) if len(name) == 0 { return nil, errInvalidParameter(paramNameName, name) |
