Google App Engine Golang no such file or directory

前端 未结 1 1148
离开以前
离开以前 2021-01-23 09:12

I am developing a Google App Engine project in go and got stuck at reading files. In fact app works perfectly locally. However when deployed, it panics telling me that there is

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-23 09:54

    When you upload/deploy your application, application files and static files are stored separately. Static files are served by specialized/dedicated servers, not by your frontend instances.

    That means if you have a file which you want to read from your Go code, that file must not match any static file pattern and cannot be in a folder specified as a static directory, else the file will be considered a static file and will not be deployed next to your Go code.

    This is detailed on the Application configuration page, Section Static file handlers. Quoting the relevant part:

    For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.

    If there is a file which you want to be both a static file and an application file, you have 2 options:

    1) You may duplicate it, e.g. put it next to your code and to a separate folder (e.g. static) which you can mark as a static dir.

    Or (preferred):

    2) Specify the application_readable option to the static file handler which includes/applies to the file. Quoting from the documentation:

    Optional. By default, files declared in static file handlers are uploaded as static data and are only served to end users, they cannot be read by an application. If this field is set to true, the files are also uploaded as code data so your application can read them. Both uploads are charged against your code and static data storage resource quotas.

    0 讨论(0)
提交回复
热议问题