mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
Full rebrand of the SigNoz observability platform: - Go module: github.com/SigNoz/signoz → github.com/hanzoai/o11y - Frontend: @signozhq/* → @hanzo/o11y-*, posthog-js → @hanzo/insights - Docker: signoz/* → ghcr.io/hanzoai/o11y* - ClickHouse → Hanzo Datastore (hanzoai/datastore) - Env vars: SIGNOZ_* → HANZO_* - DB tables: signoz_* → o11y_* - All branding, URLs, docs updated - 2172 files changed
53 lines
940 B
Go
53 lines
940 B
Go
package types
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/hanzoai/o11y/pkg/errors"
|
|
)
|
|
|
|
// Do not take inspiration from this. This is a hack to avoid using valuer.String and use upper case strings.
|
|
type Role string
|
|
|
|
const (
|
|
RoleAdmin Role = "ADMIN"
|
|
RoleEditor Role = "EDITOR"
|
|
RoleViewer Role = "VIEWER"
|
|
)
|
|
|
|
func NewRole(role string) (Role, error) {
|
|
switch role {
|
|
case "ADMIN":
|
|
return RoleAdmin, nil
|
|
case "EDITOR":
|
|
return RoleEditor, nil
|
|
case "VIEWER":
|
|
return RoleViewer, nil
|
|
}
|
|
|
|
return "", errors.Newf(errors.TypeInvalidInput, errors.CodeInvalidInput, "invalid role: %s", role)
|
|
}
|
|
|
|
func (r Role) String() string {
|
|
return string(r)
|
|
}
|
|
|
|
func (r *Role) UnmarshalJSON(data []byte) error {
|
|
var s string
|
|
if err := json.Unmarshal(data, &s); err != nil {
|
|
return err
|
|
}
|
|
|
|
role, err := NewRole(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*r = role
|
|
return nil
|
|
}
|
|
|
|
func (r Role) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(r.String())
|
|
}
|