Add a new profile to your Revel project
Conf/my.conf, the contents are as follows:
# Site Information Configuration
[Website]
website.version=1.0
website.sitedomain=
On-line search for half a day, unexpectedly did not find Revel configuration How to read, began to directly use the "Github.com/robfig/config" library (of course Revel itself also use this library), this is my database configuration
//determine if the separator is a systemSeparator: ="/" ifOs. Ispathseparator ('\\') {Separator="\\" } Else{Separator="/"} config_file:= (Revel. BasePath +"/conf/database.conf") Config_file= Strings. Replace (Config_file,"/", Separator,-1) C, _:=CONFIG. Readdefault (Config_file) Db_driver, _:= C.string ("Database","Db.driver") Db_dbname, _:= C.string ("Database","Db.dbname") Db_user, _:= C.string ("Database","Db.user") Db_password, _:= C.string ("Database","Db.password") Db_host, _:= C.string ("Database","Db.host") //Db_prefix, _: = c.string ("Database", "Db.prefix")Fmt. Println (Db_driver)
Can be used, later thought, Revel itself should be implemented to read the configuration file function only, through the Revel configuration of the view found Revel. Loadconfig () method, try to use the
conf, err: = Revel. Loadconfig ("my.conf") if err ! = nil { FMT. PRINTLN (Err) } fmt. Println (CONF. Raw (). String ("website" "website.version"))//successfully prints out the result, You can also replace string () with rawstring ()
Originally thought can be directly like using Revel. Config.string ("website.version") such acquisition, the results can not, first, then continue to learn to see
On Go Revel Two