GoDoxy/internal/homepage/homepage.go
Yuzerion 4a8bd48ad5
Some checks are pending
Docker Image CI (socket-proxy) / build (push) Waiting to run
fix: optimize memory usage, fix agent and code refactor (#118)
* refactor: simplify io code and make utils module independent

* fix(docker): agent and socket-proxy docker event flushing with modified reverse proxy handler

* refactor: remove unused code

* refactor: remove the use of logging module in most code

* refactor: streamline domain mismatch check in certState function

* tweak: use ecdsa p-256 for autocert

* fix(tests): update health check tests for invalid host and add case for port in host

* feat(acme): custom acme directory

* refactor: code refactor and improved context and error handling

* tweak: optimize memory usage under load

* fix(oidc): restore old user matching behavior

* docs: add ChatGPT assistant to README

---------

Co-authored-by: yusing <yusing@6uo.me>
2025-05-25 09:45:57 +08:00

74 lines
1.6 KiB
Go

package homepage
import (
"encoding/json"
"slices"
"github.com/yusing/go-proxy/internal/homepage/widgets"
"github.com/yusing/go-proxy/internal/serialization"
)
type (
Homepage map[string]Category
Category []*Item
ItemConfig struct {
Show bool `json:"show"`
Name string `json:"name"` // display name
Icon *IconURL `json:"icon"`
Category string `json:"category"`
Description string `json:"description" aliases:"desc"`
SortOrder int `json:"sort_order"`
}
Item struct {
*ItemConfig
WidgetConfig *widgets.Config `json:"widget_config,omitempty" aliases:"widget"`
Alias string
Provider string
OriginURL string
}
)
func init() {
serialization.RegisterDefaultValueFactory(func() *ItemConfig {
return &ItemConfig{
Show: true,
}
})
}
func (cfg *ItemConfig) GetOverride(alias string) *ItemConfig {
return overrideConfigInstance.GetOverride(alias, cfg)
}
func (item *Item) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"show": item.Show,
"alias": item.Alias,
"provider": item.Provider,
"name": item.Name,
"icon": item.Icon,
"category": item.Category,
"description": item.Description,
"sort_order": item.SortOrder,
"widget_config": item.WidgetConfig,
})
}
func (c Homepage) Add(item *Item) {
if c[item.Category] == nil {
c[item.Category] = make(Category, 0)
}
c[item.Category] = append(c[item.Category], item)
slices.SortStableFunc(c[item.Category], func(a, b *Item) int {
if a.SortOrder < b.SortOrder {
return -1
}
if a.SortOrder > b.SortOrder {
return 1
}
return 0
})
}