On Go Revel Two

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.