From f9c01618f3a59c257ee601d3cf4de5b0e3d73675 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Wed, 29 Sep 2021 00:37:57 +0700 Subject: 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". --- http_server.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'http_server.go') 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) -- cgit v1.3