feaT: Allow specifying custom headers in the rio.json
This commit is contained in:
38
internal/context/cache.go
Normal file
38
internal/context/cache.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type RepositoryInformation struct {
|
||||
// Headers to include in every response
|
||||
Headers map[string]string
|
||||
}
|
||||
|
||||
func repoInfoKey(owner, name string) string {
|
||||
return owner + ":" + name
|
||||
}
|
||||
|
||||
func (c *CacheContext) GetRepositoryInformation(owner, repoName string) *RepositoryInformation {
|
||||
data, found := c.RepositoryInformationCache.Get(repoInfoKey(owner, repoName))
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
|
||||
typedData := data.(RepositoryInformation)
|
||||
return &typedData
|
||||
}
|
||||
|
||||
func (c *CacheContext) SetRepositoryInformation(owner, repoName string, info RepositoryInformation) {
|
||||
c.RepositoryInformationCache.Set(
|
||||
repoInfoKey(owner, repoName),
|
||||
info,
|
||||
cache.DefaultExpiration,
|
||||
)
|
||||
}
|
||||
|
||||
func MakeRepoInfoCache() cache.Cache {
|
||||
return *cache.New(24*time.Hour, 12*time.Hour)
|
||||
}
|
||||
@@ -3,15 +3,22 @@ package context
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.polynom.me/rio/internal/gitea"
|
||||
"git.polynom.me/rio/internal/metrics"
|
||||
"git.polynom.me/rio/internal/repo"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type CacheContext struct {
|
||||
// Cache for general repository information
|
||||
RepositoryInformationCache cache.Cache
|
||||
}
|
||||
|
||||
type GlobalContext struct {
|
||||
DefaultCSP string
|
||||
PagesDomain string
|
||||
Gitea *repo.GiteaClient
|
||||
Gitea *gitea.GiteaClient
|
||||
MetricConfig *metrics.LokiMetricConfig
|
||||
Cache *CacheContext
|
||||
}
|
||||
|
||||
type Context struct {
|
||||
|
||||
Reference in New Issue
Block a user