4267a229创建于 2024年8月2日历史提交
/*
    Copyright (c) [2023] [squallzhao]
    fountain is licensed under APACHE LICENSE, VERSION 2.0.
    You can use this software according to the terms and conditions of the APACHE LICENSE, VERSION 2.0.
    You may obtain a copy of APACHE LICENSE, VERSION 2.0 at: https://www.apache.org/licenses/LICENSE-2.0
*/
package microservice.config
import std.collection.*
import std.fs.*
import std.io.*
import microservice.trace.*

public class Properties{
    let propertiiesMap = HashMap<String, String>()

    public func load(fileName: String): Unit{
        var fs: File = File(fileName,OpenOption.Open(true, false))
        var reader = StringReader(fs)
        while(true){
            var line = reader.readln();
            if (let Some(v) <- line){
                var arr = v.split('=')
                if (arr.size==2){
                    setProperty(arr[0], arr[1])
                }
            } else{
                break
            }
        }
        fs.close();
    }

    public func getProperty(key: String): Option<String>{
        return propertiiesMap.get(key);
    }

    public func setProperty(key: String, value: String): Option<String>{
        return propertiiesMap.put(key, value);
    }

    public func dump(){
        for ( (k,v) in propertiiesMap){
            Logger.trace("k="+k+", v="+v)
        }
    }
}