lottsa stuff

This commit is contained in:
2025-01-19 20:17:57 -06:00
parent 88ecb1bc24
commit 2be7b117ea
8 changed files with 424 additions and 0 deletions

51
steamcache/config.go Normal file
View File

@@ -0,0 +1,51 @@
package steamcache
import "github.com/docker/go-units"
type StorageType string
type Config struct {
Address string `yaml:"address"` // Address to listen on
Storage []StorageConfig `yaml:"storage"` // Storage configuration
// Ordered by speed so memory is first, then ssd, then hdd, etc
}
func NewConfig() *Config {
return &Config{
Address: ":8080",
Storage: []StorageConfig{
{
Name: "memory",
MaxSizeStr: "1GB",
},
{
Name: "filesystem",
Path: "/example/path",
MaxSizeStr: "1TB",
},
},
}
}
type StorageConfig struct {
Name string `yaml:"name"` // Name of the storage
Path string `yaml:"path,omitempty"` // Path to the storage (if applicable) - empty for memory
MaxSizeStr string `yaml:"max_size"` // Maximum size of the storage in human readable format (e.g. 1GB)
}
func (sc *StorageConfig) IsMemory() bool {
return sc.Path == ""
}
func (sc *StorageConfig) IsFilesystem() bool {
return sc.Path != ""
}
func (sc *StorageConfig) MaxSize() int64 {
x, err := units.FromHumanSize(sc.MaxSizeStr)
if err != nil {
return -1 // Unlimited
}
return x // Bytes
}

21
steamcache/steamcache.go Normal file
View File

@@ -0,0 +1,21 @@
package steamcache
import "net/http"
type SteamCache struct {
}
func New() *SteamCache {
return &SteamCache{}
}
func (sc *SteamCache) Run() {
http.ListenAndServe(":8080", sc)
}
func (sc *SteamCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
//TODO: proxy request to steam servers and cache the response
// for now, just return a simple response
w.Write([]byte("Hello, World!"))
}