package util

import (
	"ARKItems/entity/ark"
	"encoding/json"
	"io"
	"os"
	"strings"
)

//读取ark shop配置

func LoadArkShopConfig(url string) ark.Config {
	file, err := os.OpenFile(url, os.O_RDWR, 0666)
	if err != nil {
		panic(err)
	}
	defer file.Close()
	all, err := io.ReadAll(file)
	if err != nil {
		panic(err)
	}
	index := strings.Index(string(all), "{")
	all = []byte(string(all)[index:])

	return LoadArkShopConfigByString(all)
}

func LoadArkShopConfigByString(jsonContent []byte) ark.Config {
	var config ark.Config
	err := json.Unmarshal(jsonContent, &config)
	if err != nil {
		panic(err)
	}
	return config
}
