package gcpsso

import (
	"github.com/go-ini/ini"
	"strings"
)

const inifile_path = `./config/gcp_custom_role.ini`

func Read_ini_value(item string) (error, []string) {
	// 加载 INI 文件
	cfg, err := ini.Load(inifile_path)
	if err != nil {
		return err, nil
	}

	// 读取一个键值对
	/*
		section := cfg.Section("") // 默认节
		key := section.Key("app_name").String()
		fmt.Println("App Name:", key)
	*/

	// 读取一个节中的键值对
	dbSection := cfg.Section(item)
	roles := dbSection.Key("roles").String()

	roles = strings.TrimSpace(roles)
	roles = strings.TrimLeft(roles, "\n")
	roles = strings.TrimRight(roles, "\n")

	roles_spi := strings.Split(roles, "|")

	return nil, roles_spi

	// 遍历所有节和键值对
	/*
		for _, section := range cfg.Sections() {
			fmt.Println("Section:", section.Name())
			for _, key := range section.Keys() {
				fmt.Printf("Key: %s, Value: %s\n", key.Name(), key.String())
			}
		}
	*/
}
