// Code generated by hostgen. DO NOT EDIT. // // This file contains client wrappers for the Cache host service. // It is intended for use in Navidrome plugins built with TinyGo. // //go:build wasip1 package main import ( "encoding/json" "errors" "github.com/extism/go-pdk" ) // cache_setstring is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_setstring func cache_setstring(uint64) uint64 // cache_getstring is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_getstring func cache_getstring(uint64) uint64 // cache_setint is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_setint func cache_setint(uint64) uint64 // cache_getint is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_getint func cache_getint(uint64) uint64 // cache_setfloat is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_setfloat func cache_setfloat(uint64) uint64 // cache_getfloat is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_getfloat func cache_getfloat(uint64) uint64 // cache_setbytes is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_setbytes func cache_setbytes(uint64) uint64 // cache_getbytes is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_getbytes func cache_getbytes(uint64) uint64 // cache_has is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_has func cache_has(uint64) uint64 // cache_remove is the host function provided by Navidrome. // //go:wasmimport extism:host/user cache_remove func cache_remove(uint64) uint64 // CacheSetStringRequest is the request type for Cache.SetString. type CacheSetStringRequest struct { Key string `json:"key"` Value string `json:"value"` TtlSeconds int64 `json:"ttlSeconds"` } // CacheSetStringResponse is the response type for Cache.SetString. type CacheSetStringResponse struct { Error string `json:"error,omitempty"` } // CacheGetStringRequest is the request type for Cache.GetString. type CacheGetStringRequest struct { Key string `json:"key"` } // CacheGetStringResponse is the response type for Cache.GetString. type CacheGetStringResponse struct { Value string `json:"value,omitempty"` Exists bool `json:"exists,omitempty"` Error string `json:"error,omitempty"` } // CacheSetIntRequest is the request type for Cache.SetInt. type CacheSetIntRequest struct { Key string `json:"key"` Value int64 `json:"value"` TtlSeconds int64 `json:"ttlSeconds"` } // CacheSetIntResponse is the response type for Cache.SetInt. type CacheSetIntResponse struct { Error string `json:"error,omitempty"` } // CacheGetIntRequest is the request type for Cache.GetInt. type CacheGetIntRequest struct { Key string `json:"key"` } // CacheGetIntResponse is the response type for Cache.GetInt. type CacheGetIntResponse struct { Value int64 `json:"value,omitempty"` Exists bool `json:"exists,omitempty"` Error string `json:"error,omitempty"` } // CacheSetFloatRequest is the request type for Cache.SetFloat. type CacheSetFloatRequest struct { Key string `json:"key"` Value float64 `json:"value"` TtlSeconds int64 `json:"ttlSeconds"` } // CacheSetFloatResponse is the response type for Cache.SetFloat. type CacheSetFloatResponse struct { Error string `json:"error,omitempty"` } // CacheGetFloatRequest is the request type for Cache.GetFloat. type CacheGetFloatRequest struct { Key string `json:"key"` } // CacheGetFloatResponse is the response type for Cache.GetFloat. type CacheGetFloatResponse struct { Value float64 `json:"value,omitempty"` Exists bool `json:"exists,omitempty"` Error string `json:"error,omitempty"` } // CacheSetBytesRequest is the request type for Cache.SetBytes. type CacheSetBytesRequest struct { Key string `json:"key"` Value []byte `json:"value"` TtlSeconds int64 `json:"ttlSeconds"` } // CacheSetBytesResponse is the response type for Cache.SetBytes. type CacheSetBytesResponse struct { Error string `json:"error,omitempty"` } // CacheGetBytesRequest is the request type for Cache.GetBytes. type CacheGetBytesRequest struct { Key string `json:"key"` } // CacheGetBytesResponse is the response type for Cache.GetBytes. type CacheGetBytesResponse struct { Value []byte `json:"value,omitempty"` Exists bool `json:"exists,omitempty"` Error string `json:"error,omitempty"` } // CacheHasRequest is the request type for Cache.Has. type CacheHasRequest struct { Key string `json:"key"` } // CacheHasResponse is the response type for Cache.Has. type CacheHasResponse struct { Exists bool `json:"exists,omitempty"` Error string `json:"error,omitempty"` } // CacheRemoveRequest is the request type for Cache.Remove. type CacheRemoveRequest struct { Key string `json:"key"` } // CacheRemoveResponse is the response type for Cache.Remove. type CacheRemoveResponse struct { Error string `json:"error,omitempty"` } // CacheSetString calls the cache_setstring host function. // SetString stores a string value in the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // - value: The string value to store // - ttlSeconds: Time-to-live in seconds (0 uses default of 24 hours) // // Returns an error if the operation fails. func CacheSetString(key string, value string, ttlSeconds int64) (*CacheSetStringResponse, error) { // Marshal request to JSON req := CacheSetStringRequest{ Key: key, Value: value, TtlSeconds: ttlSeconds, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_setstring(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheSetStringResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheGetString calls the cache_getstring host function. // GetString retrieves a string value from the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a string, exists will be false. func CacheGetString(key string) (*CacheGetStringResponse, error) { // Marshal request to JSON req := CacheGetStringRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_getstring(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheGetStringResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheSetInt calls the cache_setint host function. // SetInt stores an integer value in the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // - value: The integer value to store // - ttlSeconds: Time-to-live in seconds (0 uses default of 24 hours) // // Returns an error if the operation fails. func CacheSetInt(key string, value int64, ttlSeconds int64) (*CacheSetIntResponse, error) { // Marshal request to JSON req := CacheSetIntRequest{ Key: key, Value: value, TtlSeconds: ttlSeconds, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_setint(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheSetIntResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheGetInt calls the cache_getint host function. // GetInt retrieves an integer value from the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not an integer, exists will be false. func CacheGetInt(key string) (*CacheGetIntResponse, error) { // Marshal request to JSON req := CacheGetIntRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_getint(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheGetIntResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheSetFloat calls the cache_setfloat host function. // SetFloat stores a float value in the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // - value: The float value to store // - ttlSeconds: Time-to-live in seconds (0 uses default of 24 hours) // // Returns an error if the operation fails. func CacheSetFloat(key string, value float64, ttlSeconds int64) (*CacheSetFloatResponse, error) { // Marshal request to JSON req := CacheSetFloatRequest{ Key: key, Value: value, TtlSeconds: ttlSeconds, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_setfloat(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheSetFloatResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheGetFloat calls the cache_getfloat host function. // GetFloat retrieves a float value from the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a float, exists will be false. func CacheGetFloat(key string) (*CacheGetFloatResponse, error) { // Marshal request to JSON req := CacheGetFloatRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_getfloat(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheGetFloatResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheSetBytes calls the cache_setbytes host function. // SetBytes stores a byte slice in the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // - value: The byte slice to store // - ttlSeconds: Time-to-live in seconds (0 uses default of 24 hours) // // Returns an error if the operation fails. func CacheSetBytes(key string, value []byte, ttlSeconds int64) (*CacheSetBytesResponse, error) { // Marshal request to JSON req := CacheSetBytesRequest{ Key: key, Value: value, TtlSeconds: ttlSeconds, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_setbytes(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheSetBytesResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheGetBytes calls the cache_getbytes host function. // GetBytes retrieves a byte slice from the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a byte slice, exists will be false. func CacheGetBytes(key string) (*CacheGetBytesResponse, error) { // Marshal request to JSON req := CacheGetBytesRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_getbytes(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheGetBytesResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheHas calls the cache_has host function. // Has checks if a key exists in the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // // Returns true if the key exists and has not expired. func CacheHas(key string) (*CacheHasResponse, error) { // Marshal request to JSON req := CacheHasRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_has(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheHasResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil } // CacheRemove calls the cache_remove host function. // Remove deletes a value from the cache. // // Parameters: // - key: The cache key (will be namespaced with plugin ID) // // Returns an error if the operation fails. Does not return an error if the key doesn't exist. func CacheRemove(key string) (*CacheRemoveResponse, error) { // Marshal request to JSON req := CacheRemoveRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { return nil, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() // Call the host function responsePtr := cache_remove(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response var response CacheRemoveResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil, err } // Convert Error field to Go error if response.Error != "" { return nil, errors.New(response.Error) } return &response, nil }