Documentation ¶
Index ¶
- type SyncFile
- func (s *SyncFile) Apply() error
- func (s *SyncFile) Change(new []byte) error
- func (s *SyncFile) Contents() []byte
- func (s *SyncFile) Control() chan command
- func (s *SyncFile) Error() error
- func (s *SyncFile) Exit(wait bool)
- func (s *SyncFile) Filename() string
- func (s *SyncFile) GetString() string
- func (s *SyncFile) Interval() time.Duration
- func (s *SyncFile) ModTime() time.Time
- func (s *SyncFile) Reload() error
- func (s *SyncFile) RunCommand(cmd command)
- type SyncJSON
- func (s *SyncJSON) Array() []gjson.Result
- func (s *SyncJSON) Get(key string) gjson.Result
- func (s *SyncJSON) GetArray(key string) []gjson.Result
- func (s *SyncJSON) GetArrayOfInt(key string) []int
- func (s *SyncJSON) GetArrayOfString(key string) []string
- func (s *SyncJSON) GetBool(key string) bool
- func (s *SyncJSON) GetFloat(key string) float64
- func (s *SyncJSON) GetInt(key string) int
- func (s *SyncJSON) GetString(key string) string
- func (s *SyncJSON) Map() map[string]gjson.Result
- type SyncStructController
- func (s *SyncStructController) AddEventListener(name string, f func(string, gjson.Result, gjson.Result) error)
- func (s *SyncStructController) Apply() error
- func (s *SyncStructController) Error() error
- func (s *SyncStructController) Exit(wait bool)
- func (s *SyncStructController) Filename() string
- func (s *SyncStructController) Interval() time.Duration
- func (s *SyncStructController) ModTime() time.Time
- func (s *SyncStructController) Reload() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SyncFile ¶
type SyncFile struct {
// contains filtered or unexported fields
}
A file object that will be synchronized with the target file. If you change the file directly, SyncFile will reload contents from the file. If you change the contents in SyncFile, changes will be applied to the file. Warning: All contents in the file will be loaded into memory, Please be careful to the size of the file.
func NewSyncFile ¶
Create a SyncFile object.
func (*SyncFile) Contents ¶
Access to contents directly Important: If you changed the contents directly, You need run the Apply() function to apply changes.
type SyncJSON ¶
A json dictionary file object that will be synchronized with the target file. If you change the file directly, SyncJSON will reload contents from the file. If you change the contents in SyncJSON, changes will be applied to the file. Warning: All contents in the file will be loaded into memory, Please be careful to the size of the file.
func NewSyncJSON ¶
Create a SyncJSON object.
func (*SyncJSON) GetArrayOfInt ¶
Get value as a array of int.
func (*SyncJSON) GetArrayOfString ¶
Get value as a array of string.
type SyncStructController ¶
type SyncStructController struct {
// contains filtered or unexported fields
}
This controller can stop the sync-goroutines
func SyncStructWithJsonFile ¶
func SyncStructWithJsonFile(structData interface{}, filename string, interval time.Duration) (*SyncStructController, error)
Create a goroutine to synchronize the data. If you want to stop the sync-goroutines, Use SyncStructController.Exit()
func (*SyncStructController) AddEventListener ¶
func (s *SyncStructController) AddEventListener(name string, f func(string, gjson.Result, gjson.Result) error)
Add a event listener. When the value of this field in json file was changed, the listener function will be called. func(name string, old gjson.Result, new gjson.Result) error Important: name parameter is the field name in json file not in the struct. For example:
type Sample struct { Name string `json:"name"` <--- This json tag. Age int `json:"age"` }
If you want to add a event listener to `Name` field, the name parameter must be "name"
func (*SyncStructController) Apply ¶
func (s *SyncStructController) Apply() error
Apply changes to file.
func (*SyncStructController) Exit ¶
func (s *SyncStructController) Exit(wait bool)
Stop sync-goroutines.
func (*SyncStructController) Filename ¶
func (s *SyncStructController) Filename() string
Get filename
func (*SyncStructController) Interval ¶
func (s *SyncStructController) Interval() time.Duration
Get interval
func (*SyncStructController) ModTime ¶
func (s *SyncStructController) ModTime() time.Time
Get modification time.
func (*SyncStructController) Reload ¶
func (s *SyncStructController) Reload() error
Reload the file manually.