8000 panic: interface conversion · Issue #80 · gookit/cache · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

panic: interface conversion #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
artemklevtsov opened this issue Jan 8, 2023 · 0 comments
Open

panic: interface conversion #80

artemklevtsov opened this issue Jan 8, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@artemklevtsov
Copy link
artemklevtsov commented Jan 8, 2023

I got panic when try to get cache value with multiple runs.

panic: interface conversion: interface {} is []interface {}, not main.Users

Code to reproduce. Try this code 2 times.

package main

import (
	"fmt"
	"os"
	"path/filepath"
	"time"

	"github.com/gookit/cache"
)

type User struct {
	Name string
}

type Users []*User

const key = "user1"

func main() {
	if cache.Has(key) {
		u, ok := cache.Get("user1").(Users)
		if !ok {
			panic("can not assert cache data")
		}
		fmt.Printf("%#v\n", u[0])
	}
	u := Users{&User{Name: "TestUser"}}
	cache.Set(key, u, 1*time.Hour)
	if cache.Has(key) {
		fmt.Println("cache written")
		u2, ok := cache.Get("user1").(Users)
		if !ok || u[0] != u2[0] {
			fmt.Println("cache data is not OK")
		} else {
			fmt.Println("cache is ok")
		}
	}
}

func init() {
	cache.Register(cache.DvrFile, cache.NewFileCache(filepath.Join(os.TempDir(), "tcache-dir")))
}

First time:

cache written
cache is ok

Second time:

panic: can not assert cache data

goroutine 1 [running]:
main.main()
        /run/media/unikum/UNIKUM-STORAGE/private/prog/go/tcache/main.go:24 +0x28a
exit status 2
@inhere inhere self-assigned this Jan 8, 2023
@inhere inhere added the bug Something isn't working label Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
0