Files
vm/controllers/base.go
zeekayandGitHub f7321c9463 build(visor): GOEXPERIMENT=jsonv2 per SCALE_STANDARD (#8)
* refactor: import github.com/hanzoai/iam (drop iamsdk/v2)

Switch from github.com/hanzoai/iamsdk/v2/iamsdk to canonical
github.com/hanzoai/iam root package. One canonical path, no drift.
Pinned to iam@86e34e93 SHA pseudo-version until v1.16.2 ships.

* build(visor): GOEXPERIMENT=jsonv2 in Dockerfile per SCALE_STANDARD

Per SCALE_STANDARD.md §2 — every Go production Dockerfile that emits
JSON to a client builds with GOEXPERIMENT=jsonv2. Verified on
hanzoai/zip's json_bench_test.go:
- Edge POST roundtrip: -12% time, -23% allocs
- Marshal-only: -22% time
- Unmarshal-only: -19% time, -25% allocs

build.sh inherits the ENV from the parent ARG so the existing go-build
invocation picks up jsonv2 unchanged. The conn-memory regression test
is deferred to a follow-up that migrates visor's beego v1.12 listener
to zip per §9 step-1.
2026-05-29 21:05:29 -07:00

99 lines
2.0 KiB
Go

// Copyright 2023 Hanzo Industries Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package controllers
import (
"encoding/gob"
"github.com/beego/beego"
iam "github.com/hanzoai/iam"
)
type ApiController struct {
beego.Controller
}
func init() {
gob.Register(iam.Claims{})
}
func GetUserName(user *iam.User) string {
if user == nil {
return ""
}
return user.Name
}
func wrapActionResponse(affected bool, e ...error) *Response {
if len(e) != 0 && e[0] != nil {
return &Response{Status: "error", Msg: e[0].Error()}
} else if affected {
return &Response{Status: "ok", Msg: "", Data: "Affected"}
} else {
return &Response{Status: "ok", Msg: "", Data: "Unaffected"}
}
}
func (c *ApiController) GetSessionClaims() *iam.Claims {
s := c.GetSession("user")
if s == nil {
return nil
}
claims := s.(iam.Claims)
return &claims
}
func (c *ApiController) SetSessionClaims(claims *iam.Claims) {
if claims == nil {
c.DelSession("user")
return
}
c.SetSession("user", *claims)
}
func (c *ApiController) GetSessionUser() *iam.User {
claims := c.GetSessionClaims()
if claims == nil {
return nil
}
return &claims.User
}
func (c *ApiController) SetSessionUser(user *iam.User) {
if user == nil {
c.DelSession("user")
return
}
claims := c.GetSessionClaims()
if claims != nil {
claims.User = *user
c.SetSessionClaims(claims)
}
}
func (c *ApiController) GetSessionUsername() string {
user := c.GetSessionUser()
if user == nil {
return ""
}
return GetUserName(user)
}