file

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2020 License: BSD-3-Clause Imports: 7 Imported by: 2

README

Joe Bot - File Storage

Basic file storage memory adapater. https://github.com/go-joe/joe


This repository contains a module for the Joe Bot library.

Getting Started

This library is packaged as Go module. You can get it via:

go get github.com/go-joe/file-memory

Example usage

b := &ExampleBot{
	Bot: joe.New("example", file.Memory("foobar.json")),
}

Built With

  • testify - A simple unit test library
  • zap - Blazing fast, structured, leveled logging in Go

Contributing

If you want to hack on this repository, please read the short CONTRIBUTING.md guide first.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Friedrich Große - Initial work - fgrosse
  • Stefan Warman - Unit tests - warmans

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

Documentation

Overview

Package file implements file based memory for the Joe bot library. https://github.com/go-joe/joe

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Memory

func Memory(path string) joe.Module

Memory is a joe.Option which is supposed to be passed to joe.New(…) to configure a new bot. The path indicates the destination file at which the memory will store its values encoded as JSON object. If there is already a JSON encoded file at the given path it will be loaded and decoded into memory to serve future requests. If the file exists but cannot be opened or does not contain a valid JSON object its error will be deferred until the bot is actually started via its Run() function.

Example usage:

b := joe.New("example",
    file.Memory("/tmp/joe.json"),
    …
)

func NewMemory

func NewMemory(path string, opts ...Option) (joe.Memory, error)

NewMemory creates a new Memory instance that persists all values to the given path. If there is already a JSON encoded file at the given path it is loaded and decoded into memory to serve future requests. An error is returned if the file exists but cannot be opened or does not contain a valid JSON object.

Types

type Option

type Option func(*memory) error

Option corresponds to a configuration setting of the file memory. All available options are the exported functions of this package that share the prefix "With" in their names.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger is a memory option that allows the caller to set a different logger. By default this option is not required because the file.Memory(…) function automatically uses the logger of the given joe.Config.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL