cleaned up RC() and SetRC() in AmContext (no longer needed)
This commit is contained in:
@@ -52,7 +52,6 @@ type AmContext interface {
|
|||||||
IsMember() bool
|
IsMember() bool
|
||||||
IsMemberLocked() bool
|
IsMemberLocked() bool
|
||||||
LeftMenu() string
|
LeftMenu() string
|
||||||
RC() int
|
|
||||||
OutputType() string
|
OutputType() string
|
||||||
Parameter(string) string
|
Parameter(string) string
|
||||||
QueryParamInt(string, int) int
|
QueryParamInt(string, int) int
|
||||||
@@ -64,7 +63,6 @@ type AmContext interface {
|
|||||||
SetLeftMenu(string)
|
SetLeftMenu(string)
|
||||||
SetLoginCookie(string)
|
SetLoginCookie(string)
|
||||||
SetOutputType(string)
|
SetOutputType(string)
|
||||||
SetRC(int)
|
|
||||||
GetScratch(string) any
|
GetScratch(string) any
|
||||||
SetScratch(string, any)
|
SetScratch(string, any)
|
||||||
GetSession(string) any
|
GetSession(string) any
|
||||||
@@ -86,7 +84,6 @@ type AmContext interface {
|
|||||||
// amContext is the internal structure that implements AmContext.
|
// amContext is the internal structure that implements AmContext.
|
||||||
type amContext struct {
|
type amContext struct {
|
||||||
echoContext echo.Context
|
echoContext echo.Context
|
||||||
httprc int
|
|
||||||
rendervars jet.VarMap
|
rendervars jet.VarMap
|
||||||
outputType string
|
outputType string
|
||||||
session AmSession
|
session AmSession
|
||||||
@@ -265,11 +262,6 @@ func (c *amContext) LeftMenu() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RC returns the HTTP result code for the current operation.
|
|
||||||
func (c *amContext) RC() int {
|
|
||||||
return c.httprc
|
|
||||||
}
|
|
||||||
|
|
||||||
// OutputType returns the MIME output type set for the current operation.
|
// OutputType returns the MIME output type set for the current operation.
|
||||||
func (c *amContext) OutputType() string {
|
func (c *amContext) OutputType() string {
|
||||||
return c.outputType
|
return c.outputType
|
||||||
@@ -379,11 +371,6 @@ func (c *amContext) SetOutputType(typ string) {
|
|||||||
c.outputType = typ
|
c.outputType = typ
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRC sets the HTTP result code for the current operation.
|
|
||||||
func (c *amContext) SetRC(rc int) {
|
|
||||||
c.httprc = rc
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScratch returns a value in the per-request scratchpad.
|
// GetScratch returns a value in the per-request scratchpad.
|
||||||
func (c *amContext) GetScratch(name string) any {
|
func (c *amContext) GetScratch(name string) any {
|
||||||
return c.echoContext.Get("am." + name)
|
return c.echoContext.Get("am." + name)
|
||||||
@@ -469,7 +456,6 @@ func newContext(ctxt echo.Context) (*amContext, error) {
|
|||||||
rc := freeContext.Get()
|
rc := freeContext.Get()
|
||||||
if rc == nil {
|
if rc == nil {
|
||||||
rc = &amContext{
|
rc = &amContext{
|
||||||
httprc: http.StatusOK,
|
|
||||||
rendervars: make(jet.VarMap),
|
rendervars: make(jet.VarMap),
|
||||||
outputType: "",
|
outputType: "",
|
||||||
}
|
}
|
||||||
@@ -544,7 +530,6 @@ func AmContextFromEchoContext(ctxt echo.Context) AmContext {
|
|||||||
func contextRecycler(incoming chan *amContext, done chan bool) {
|
func contextRecycler(incoming chan *amContext, done chan bool) {
|
||||||
for c := range incoming {
|
for c := range incoming {
|
||||||
c.echoContext = nil
|
c.echoContext = nil
|
||||||
c.httprc = http.StatusOK
|
|
||||||
c.rendervars = make(jet.VarMap)
|
c.rendervars = make(jet.VarMap)
|
||||||
c.outputType = ""
|
c.outputType = ""
|
||||||
c.session = nil
|
c.session = nil
|
||||||
|
|||||||
+6
-7
@@ -37,9 +37,9 @@ import (
|
|||||||
*/
|
*/
|
||||||
func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error {
|
func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error {
|
||||||
// Preprocess certain commands into different ones.
|
// Preprocess certain commands into different ones.
|
||||||
|
httprc := http.StatusOK
|
||||||
switch command {
|
switch command {
|
||||||
case "error":
|
case "error":
|
||||||
httprc := amctxt.RC()
|
|
||||||
message := ""
|
message := ""
|
||||||
if data == nil {
|
if data == nil {
|
||||||
message = fmt.Sprintf("Unspecified error in %s", ctxt.Request().URL.String())
|
message = fmt.Sprintf("Unspecified error in %s", ctxt.Request().URL.String())
|
||||||
@@ -70,13 +70,12 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
|||||||
}
|
}
|
||||||
amctxt.VarMap().Set("amsterdam_pageTitle", "Internal Server Error")
|
amctxt.VarMap().Set("amsterdam_pageTitle", "Internal Server Error")
|
||||||
amctxt.VarMap().Set("error", message)
|
amctxt.VarMap().Set("error", message)
|
||||||
amctxt.SetRC(httprc)
|
|
||||||
command = "framed"
|
command = "framed"
|
||||||
data = "error.jet"
|
data = "error.jet"
|
||||||
case "ipban":
|
case "ipban":
|
||||||
amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned")
|
amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned")
|
||||||
amctxt.VarMap().Set("message", data)
|
amctxt.VarMap().Set("message", data)
|
||||||
amctxt.SetRC(http.StatusForbidden)
|
httprc = http.StatusForbidden
|
||||||
command = "framed"
|
command = "framed"
|
||||||
data = "ipban.jet"
|
data = "ipban.jet"
|
||||||
}
|
}
|
||||||
@@ -85,13 +84,13 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
|||||||
var err error
|
var err error
|
||||||
switch command {
|
switch command {
|
||||||
case "bytes":
|
case "bytes":
|
||||||
err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), data.([]byte))
|
err = ctxt.Blob(httprc, amctxt.OutputType(), data.([]byte))
|
||||||
case "redirect":
|
case "redirect":
|
||||||
err = ctxt.Redirect(http.StatusFound, data.(string))
|
err = ctxt.Redirect(http.StatusFound, data.(string))
|
||||||
case "string":
|
case "string":
|
||||||
err = ctxt.String(amctxt.RC(), data.(string))
|
err = ctxt.String(httprc, data.(string))
|
||||||
case "template":
|
case "template":
|
||||||
err = ctxt.Render(amctxt.RC(), data.(string), amctxt)
|
err = ctxt.Render(httprc, data.(string), amctxt)
|
||||||
case "framed":
|
case "framed":
|
||||||
amctxt.VarMap().Set("amsterdam_innerPage", data)
|
amctxt.VarMap().Set("amsterdam_innerPage", data)
|
||||||
menus := make([]*MenuDefinition, 2)
|
menus := make([]*MenuDefinition, 2)
|
||||||
@@ -109,7 +108,7 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
|||||||
}
|
}
|
||||||
menus[1] = AmMenu("fixed")
|
menus[1] = AmMenu("fixed")
|
||||||
amctxt.VarMap().Set("amsterdam_leftMenus", menus)
|
amctxt.VarMap().Set("amsterdam_leftMenus", menus)
|
||||||
err = ctxt.Render(amctxt.RC(), "frame.jet", amctxt)
|
err = ctxt.Render(httprc, "frame.jet", amctxt)
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("AmSendPageData(): unknown rendering type: %s", command)
|
err = fmt.Errorf("AmSendPageData(): unknown rendering type: %s", command)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user