cleaned up RC() and SetRC() in AmContext (no longer needed)

This commit is contained in:
2026-02-10 18:22:24 -07:00
parent 975265af58
commit 09842a91bd
2 changed files with 6 additions and 22 deletions
-15
View File
@@ -52,7 +52,6 @@ type AmContext interface {
IsMember() bool
IsMemberLocked() bool
LeftMenu() string
RC() int
OutputType() string
Parameter(string) string
QueryParamInt(string, int) int
@@ -64,7 +63,6 @@ type AmContext interface {
SetLeftMenu(string)
SetLoginCookie(string)
SetOutputType(string)
SetRC(int)
GetScratch(string) any
SetScratch(string, any)
GetSession(string) any
@@ -86,7 +84,6 @@ type AmContext interface {
// amContext is the internal structure that implements AmContext.
type amContext struct {
echoContext echo.Context
httprc int
rendervars jet.VarMap
outputType string
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.
func (c *amContext) OutputType() string {
return c.outputType
@@ -379,11 +371,6 @@ func (c *amContext) SetOutputType(typ string) {
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.
func (c *amContext) GetScratch(name string) any {
return c.echoContext.Get("am." + name)
@@ -469,7 +456,6 @@ func newContext(ctxt echo.Context) (*amContext, error) {
rc := freeContext.Get()
if rc == nil {
rc = &amContext{
httprc: http.StatusOK,
rendervars: make(jet.VarMap),
outputType: "",
}
@@ -544,7 +530,6 @@ func AmContextFromEchoContext(ctxt echo.Context) AmContext {
func contextRecycler(incoming chan *amContext, done chan bool) {
for c := range incoming {
c.echoContext = nil
c.httprc = http.StatusOK
c.rendervars = make(jet.VarMap)
c.outputType = ""
c.session = nil
+6 -7
View File
@@ -37,9 +37,9 @@ import (
*/
func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error {
// Preprocess certain commands into different ones.
httprc := http.StatusOK
switch command {
case "error":
httprc := amctxt.RC()
message := ""
if data == nil {
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("error", message)
amctxt.SetRC(httprc)
command = "framed"
data = "error.jet"
case "ipban":
amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned")
amctxt.VarMap().Set("message", data)
amctxt.SetRC(http.StatusForbidden)
httprc = http.StatusForbidden
command = "framed"
data = "ipban.jet"
}
@@ -85,13 +84,13 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
var err error
switch command {
case "bytes":
err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), data.([]byte))
err = ctxt.Blob(httprc, amctxt.OutputType(), data.([]byte))
case "redirect":
err = ctxt.Redirect(http.StatusFound, data.(string))
case "string":
err = ctxt.String(amctxt.RC(), data.(string))
err = ctxt.String(httprc, data.(string))
case "template":
err = ctxt.Render(amctxt.RC(), data.(string), amctxt)
err = ctxt.Render(httprc, data.(string), amctxt)
case "framed":
amctxt.VarMap().Set("amsterdam_innerPage", data)
menus := make([]*MenuDefinition, 2)
@@ -109,7 +108,7 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
}
menus[1] = AmMenu("fixed")
amctxt.VarMap().Set("amsterdam_leftMenus", menus)
err = ctxt.Render(amctxt.RC(), "frame.jet", amctxt)
err = ctxt.Render(httprc, "frame.jet", amctxt)
default:
err = fmt.Errorf("AmSendPageData(): unknown rendering type: %s", command)
}