Documentation
¶
Overview ¶
Package filevar provides a runtimevar.Driver implementation that reads variables from local files.
User can update a configuration file using any commands (cp, mv) or tools/editors. This package does not guarantee read consistency since it does not have control over the writes. It is highly advisable to use this package only for local development or testing purposes and not in production applications/services.
Known Issues:
* On Mac OSX, if user copies an empty file into a configuration file, Watch will not be able to detect the change since event.Op is Chmod only.
* Saving a configuration file in vim using :w will incur events Rename and Create. When the Rename event occurs, the file is temporarily removed and hence Watch will return error. A follow-up Watch call will then detect the Create event.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶ added in v0.7.0
func New(path string, decoder *runtimevar.Decoder, opts *Options) (*runtimevar.Variable, error)
New constructs a runtimevar.Variable object with this package as the driver implementation. The decoder argument allows users to dictate the decoding function to parse the file as well as the type to unmarshal into.
Example ¶
package main import ( "log" "github.com/google/go-cloud/runtimevar" "github.com/google/go-cloud/runtimevar/filevar" ) // MyAppConfig is the unmarshaled type for myapp.conf file. type MyAppConfig struct { MsgOfTheDay string `json:"msg_of_the_day"` } func main() { // Configure a JSON decoder for myapp.json to unmarshal into a MyAppConfig object. v, err := filevar.New("/etc/myapp/myapp.json", runtimevar.NewDecoder(&MyAppConfig{}, runtimevar.JSONDecode), nil) if err != nil { log.Fatalf("Error in constructing variable: %v", err) } v.Close() }
Output:
Types ¶
Directories
¶
Path | Synopsis |
---|---|
This binary demonstrates watching over a configuration file using the runtimevar package with the filevar package as the driver implementation.
|
This binary demonstrates watching over a configuration file using the runtimevar package with the filevar package as the driver implementation. |