feat: Move the CNAME into the rio.json
This commit is contained in:
@@ -11,6 +11,12 @@ import (
|
||||
type CacheContext struct {
|
||||
// Cache for general repository information
|
||||
RepositoryInformationCache cache.Cache
|
||||
|
||||
// Cache for path resolutions
|
||||
RepositoryPathCache cache.Cache
|
||||
|
||||
// Cache for username lookups
|
||||
UsernameCache cache.Cache
|
||||
}
|
||||
|
||||
type GlobalContext struct {
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
type RepositoryInformation struct {
|
||||
// Headers to include in every response
|
||||
Headers map[string]string
|
||||
|
||||
CNAME string
|
||||
}
|
||||
|
||||
func repoInfoKey(owner, name string) string {
|
||||
39
internal/context/path.go
Normal file
39
internal/context/path.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.polynom.me/rio/internal/gitea"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type RepositoryPathInformation struct {
|
||||
Repository gitea.Repository
|
||||
Path string
|
||||
}
|
||||
|
||||
func pathInfoKey(domain, path string) string {
|
||||
return domain + "/" + path
|
||||
}
|
||||
|
||||
func (c *CacheContext) GetRepositoryPath(domain, path string) *RepositoryPathInformation {
|
||||
data, found := c.RepositoryPathCache.Get(pathInfoKey(domain, path))
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
|
||||
typedData := data.(RepositoryPathInformation)
|
||||
return &typedData
|
||||
}
|
||||
|
||||
func (c *CacheContext) SetRepositoryPath(domain, path string, info RepositoryPathInformation) {
|
||||
c.RepositoryPathCache.Set(
|
||||
pathInfoKey(domain, path),
|
||||
info,
|
||||
cache.DefaultExpiration,
|
||||
)
|
||||
}
|
||||
|
||||
func MakeRepoPathCache() cache.Cache {
|
||||
return *cache.New(24*time.Hour, 12*time.Hour)
|
||||
}
|
||||
24
internal/context/user.go
Normal file
24
internal/context/user.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
func (c *CacheContext) GetUser(username string) bool {
|
||||
_, found := c.UsernameCache.Get(username)
|
||||
return found
|
||||
}
|
||||
|
||||
func (c *CacheContext) SetUser(username string) {
|
||||
c.UsernameCache.Set(
|
||||
username,
|
||||
true,
|
||||
cache.DefaultExpiration,
|
||||
)
|
||||
}
|
||||
|
||||
func MakeUsernameCache() cache.Cache {
|
||||
return *cache.New(24*time.Hour, 12*time.Hour)
|
||||
}
|
||||
Reference in New Issue
Block a user