how to read a file in directory

49 views
Skip to first unread message

dianmi...@gmail.com

unread,
Jun 20, 2013, 5:07:04 AM6/20/13
to google-ap...@googlegroups.com
Hi

I have a config file in a sub directory, like conf/app.conf, how can I read it.

I have tried 

path.join(os.GetWd(), " conf/app.conf")
path.join(os.Args[0], " conf/app.conf")
"conf/app.conf"
"./conf/app.conf"

And, another question.

How can I upload files (like conf/*.conf ) to GAE? currently I add them in app.yaml, like
- url: /conf
  static_dir: conf

but I don't want people download *.conf files via http.

I notice Java SDK can define resource_files in app.yaml, does GO SDK support it?






David Symonds

unread,
Jun 20, 2013, 8:18:05 AM6/20/13
to dianmi...@gmail.com, google-ap...@googlegroups.com
If you declare files as static (via static_files or static_dir), they
are only for serving via HTTP and are not accessible to your app. If
you only want them for your app to load, don't declare them as static.
You'll be able to read them as "conf/app.conf" or "./conf/app.conf".

David Symonds

unread,
Jun 21, 2013, 1:45:48 AM6/21/13
to Dianming Song, google-ap...@googlegroups.com
The current working directory of your app is always the top of your
app's file tree (i.e. where app.yaml is). Try opening
gwk/conf/app.conf.

Dianming Song

unread,
Jun 20, 2013, 10:20:18 PM6/20/13
to David Symonds, google-ap...@googlegroups.com
still fail to read

my files structure is 
--------
app.yaml
gwk
    conf
        app.conf
        *.conf
    public
        css
        js
        *
     views
         *
     gwk.go

app.yaml is 
--------
application: gwk-demo
version: 1
runtime: go
api_version: go1

handlers:

- url: /.*
  script: _go_app

code is
--------------

var info string

func Info(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, info)
}

func init() {

info = info + fmt.Sprintln(os.Stat("conf"))
info = info + fmt.Sprintln(os.Stat("./conf"))
info = info + fmt.Sprintln(os.Stat("conf/app.conf"))
info = info + fmt.Sprintln(os.Stat("./conf/app.conf"))

http.HandleFunc("/", Info)
}


resonse is
--------

<nil> stat conf: no such file or directory
<nil> stat ./conf: no such file or directory
<nil> stat conf/app.conf: no such file or directory
<nil> stat ./conf/app.conf: no such file or directory



2013/6/20 David Symonds <dsym...@golang.org>

Dianming Song

unread,
Jun 21, 2013, 4:16:23 AM6/21/13
to David Symonds, google-ap...@googlegroups.com
I see, should not use os.GetWd()

Thanks, It works.


2013/6/21 David Symonds <dsym...@golang.org>
Reply all
Reply to author
Forward
0 new messages