@@ -27,6 +27,7 @@ import (
2727type HTTPResponse struct {
2828 statusCode int
2929 Status string
30+ Server string
3031 ContentType string
3132}
3233
@@ -35,15 +36,16 @@ func NewHTTPResponse(statusCode int, statusMessage string) *HTTPResponse {
3536 HTTPResponse := HTTPResponse {
3637 statusCode : statusCode ,
3738 Status : "Status: " + fmt .Sprintf ("%v" , statusCode ) + " " + statusMessage + "\r \n " ,
39+ Server : "Server: synoedit " + AppVersion + "\r \n " ,
3840 ContentType : "Content-Type: text/html; charset=utf-8\r \n " ,
3941 }
4042 return & HTTPResponse
4143}
4244
4345// Print http response to stdout
4446func (HTTPResponse * HTTPResponse ) print (str ... string ) {
45- fmt .Print (HTTPResponse .Status + HTTPResponse .ContentType + " \r \n \r \n " )
46- fmt .Println (strings .Join (str , " " ))
47+ fmt .Print (HTTPResponse .Status + HTTPResponse .ContentType + HTTPResponse . Server + " \r \n " )
48+ fmt .Print (strings .Join (str , " " ))
4749 os .Exit (0 )
4850}
4951
@@ -66,3 +68,17 @@ func notFound(str ...string) {
6668 NewHTTPResponse (404 , "Not Found" ).print (strings .Join (str , " " ))
6769 os .Exit (0 )
6870}
71+
72+ // Return HTML with OK status message
73+ func okHTML (str ... string ) {
74+ NewHTTPResponse (200 , "OK" ).print (strings .Join (str , " " ))
75+ os .Exit (0 )
76+ }
77+
78+ // Return plain text with OK status message
79+ func okPlain (str ... string ) {
80+ okPlainRes := NewHTTPResponse (200 , "OK" )
81+ okPlainRes .ContentType = "Content-Type: text/plain;\r \n "
82+ okPlainRes .print (strings .Join (str , " " ))
83+ os .Exit (0 )
84+ }
0 commit comments