Files
upstream-corteza/server/pkg/envoy/resource/util.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

81 lines
1.5 KiB
Go

package resource
import (
"time"
"github.com/cortezaproject/corteza/server/compose/types"
systemTypes "github.com/cortezaproject/corteza/server/system/types"
)
func firstOkString(ss ...string) string {
for _, s := range ss {
if s != "" && s != "0" {
return s
}
}
return ""
}
// Taken (and modified) from compose/service/values/sanitizer.go
func toTime(v string) *time.Time {
ff := []string{
time.RFC3339,
time.RFC1123Z,
time.RFC1123,
time.RFC850,
time.RFC822Z,
time.RFC822,
time.RubyDate,
time.UnixDate,
time.ANSIC,
"2006/_1/_2 15:04:05",
"2006/_1/_2 15:04",
}
for _, f := range ff {
parsed, err := time.Parse(f, v)
if err == nil {
return &parsed
}
}
return nil
}
// Ref builders
func MakeNamespaceRef(id uint64, handle, name string) *Ref {
return makeGenericRef(types.NamespaceResourceType, id, handle, name)
}
func MakeModuleRef(id uint64, handle, name string) *Ref {
return makeGenericRef(types.ModuleResourceType, id, handle, name)
}
func MakePageRef(id uint64, handle, title string) *Ref {
return makeGenericRef(types.PageResourceType, id, handle, title)
}
func MakeRoleRef(id uint64, handle, name string) *Ref {
return makeGenericRef(systemTypes.RoleResourceType, id, handle, name)
}
func makeGenericRef(t string, id uint64, ii ...string) *Ref {
args := make([]interface{}, len(ii)+1)
args[0] = id
for i := range ii {
args[i+1] = ii[i]
}
aux := &Ref{
ResourceType: t,
Identifiers: identifiers(args...),
}
if t == "" || len(aux.Identifiers) == 0 {
return nil
}
return aux
}