Documentation ¶
Index ¶
- func CopyDirectory(sourceDirName, destDirName string) error
- func CopyFile(sourcePath, destPath string) error
- func Download(w http.ResponseWriter, path, name string)
- func EnableCrossDomain(w http.ResponseWriter, r *http.Request)
- func FromJSON(bytes []byte, result interface{}) error
- func Get(url string) ([]byte, error)
- func MD5(str string) string
- func PinYinToString(obj interface{}) string
- func Post(url string, data url.Values) ([]byte, error)
- func TimeToString(time time.Time, format string) string
- func ToJSON(obj interface{}) ([]byte, error)
- func UnZip(filename, path string) error
- func Write(w http.ResponseWriter, args ...interface{})
- func WriteJSON(w http.ResponseWriter, obj interface{}) error
- func Writef(w http.ResponseWriter, format string, args ...interface{})
- func Zip(dir, path string) error
- type AuthorityConfigModel
- type ConfigModel
- type DatabaseConfigModel
- type LogConfigModel
- type Mongo
- func (m Mongo) Count(collectionName string, filter interface{}) (int64, error)
- func (m Mongo) DeleteAll(collectionName string) (*mongo.DeleteResult, error)
- func (m Mongo) DeleteMany(collectionName string, filter interface{}) (*mongo.DeleteResult, error)
- func (m Mongo) DeleteOne(collectionName string, filter interface{}) (*mongo.DeleteResult, error)
- func (m Mongo) DropCollection(name string) error
- func (m Mongo) Find(collectionName string, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)
- func (m Mongo) FindAll(collectionName string, results interface{}, opts ...*options.FindOptions) (err error)
- func (m Mongo) FindMany(collectionName string, filter interface{}, results interface{}, ...) (err error)
- func (m Mongo) FindOne(collectionName string, filter interface{}, result interface{}, ...) (find bool, err error)
- func (m Mongo) GetCollection(name string) (collection *mongo.Collection, err error)
- func (m Mongo) InsertMany(collectionName string, documents []interface{}) (*mongo.InsertManyResult, error)
- func (m Mongo) InsertOne(collectionName string, document interface{}) (*mongo.InsertOneResult, error)
- func (m Mongo) ListCollectionNames() (collectionNames []string, err error)
- func (m Mongo) RunCommand(command interface{}) (result *mongo.SingleResult, err error)
- func (m Mongo) UpdateMany(collectionName string, filter interface{}, update interface{}) (*mongo.UpdateResult, error)
- func (m Mongo) UpdateOne(collectionName string, filter interface{}, update interface{}) (*mongo.UpdateResult, error)
- type PathConfigModel
- type PinYinModel
- type RemoteConfigModel
- type ServerConfigModel
- type UploadConfigModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyDirectory ¶
CopyDirectory copy the contents in one directory to another.
func Download ¶
func Download(w http.ResponseWriter, path, name string)
Download write a file stream to the webbrowser.
func EnableCrossDomain ¶
func EnableCrossDomain(w http.ResponseWriter, r *http.Request)
EnableCrossDomain enables cross domain. It set the `Access-Control-Allow-Methods` header and the `Access-Control-Allow-Origin` header.
TODO: We should restrict the origin, and may config in `config.toml`.
func PinYinToString ¶
func PinYinToString(obj interface{}) string
PinYinToString convert pinyin (string or array) to string.
TODO: Just for compatible, and will removed in the future.
func TimeToString ¶
TimeToString convert a time to string using specific format.
`yyyy-MM-dd HH:mm:ss` => 2020-05-05 20:35:12
func Write ¶
func Write(w http.ResponseWriter, args ...interface{})
Write write a string response to the web client.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, obj interface{}) error
WriteJSON write a json response to the web client.
func Writef ¶
func Writef(w http.ResponseWriter, format string, args ...interface{})
Writef write a string response to the web client with format string.
Types ¶
type AuthorityConfigModel ¶
AuthorityConfigModel is the authority config section in `config.toml`;
type ConfigModel ¶
type ConfigModel struct { Server ServerConfigModel `toml:"server"` Database DatabaseConfigModel `toml:"database"` Authority AuthorityConfigModel `toml:"authority"` Upload UploadConfigModel `toml:"upload"` Remote RemoteConfigModel `toml:"remote"` Path PathConfigModel `toml:"path"` Log LogConfigModel `toml:"log"` }
ConfigModel is the structure of file `config.toml`.
func GetConfig ¶
func GetConfig(path string) (config *ConfigModel, err error)
GetConfig read `config.toml` and parse `ConfigModel`.
type DatabaseConfigModel ¶
type DatabaseConfigModel struct { Type string `toml:"type"` Host string `toml:"host"` Port int `toml:"port"` // Connection should not read from config.toml. Connection string Database string `toml:"database"` }
DatabaseConfigModel is the database config section in `config.toml`;
type LogConfigModel ¶
type LogConfigModel struct {
File string `toml:"file"`
}
LogConfigModel is the log config section in `config.toml`;
type Mongo ¶
type Mongo struct { ConnectionString string DatabaseName string Client *mongo.Client Database *mongo.Database }
Mongo represent a mongo client.
func (Mongo) DeleteAll ¶
func (m Mongo) DeleteAll(collectionName string) (*mongo.DeleteResult, error)
DeleteAll delete all documents.
func (Mongo) DeleteMany ¶
func (m Mongo) DeleteMany(collectionName string, filter interface{}) (*mongo.DeleteResult, error)
DeleteMany delete many documents.
func (Mongo) DeleteOne ¶
func (m Mongo) DeleteOne(collectionName string, filter interface{}) (*mongo.DeleteResult, error)
DeleteOne delete one document.
func (Mongo) DropCollection ¶
DropCollection drop a collection.
func (Mongo) Find ¶
func (m Mongo) Find(collectionName string, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)
Find find a cursor from a collection.
func (Mongo) FindAll ¶
func (m Mongo) FindAll(collectionName string, results interface{}, opts ...*options.FindOptions) (err error)
FindAll find many documents of a collection.
func (Mongo) FindMany ¶
func (m Mongo) FindMany(collectionName string, filter interface{}, results interface{}, opts ...*options.FindOptions) (err error)
FindMany find many documents of a collection.
func (Mongo) FindOne ¶
func (m Mongo) FindOne(collectionName string, filter interface{}, result interface{}, opts ...*options.FindOneOptions) (find bool, err error)
FindOne find one document from a collection.
func (Mongo) GetCollection ¶
func (m Mongo) GetCollection(name string) (collection *mongo.Collection, err error)
GetCollection get a collection from collectionName.
func (Mongo) InsertMany ¶
func (m Mongo) InsertMany(collectionName string, documents []interface{}) (*mongo.InsertManyResult, error)
InsertMany insert many documents to a collection.
func (Mongo) InsertOne ¶
func (m Mongo) InsertOne(collectionName string, document interface{}) (*mongo.InsertOneResult, error)
InsertOne insert one document to a collection.
func (Mongo) ListCollectionNames ¶
ListCollectionNames list collectionNames of database.
func (Mongo) RunCommand ¶
func (m Mongo) RunCommand(command interface{}) (result *mongo.SingleResult, err error)
RunCommand run a mongo command.
func (Mongo) UpdateMany ¶
func (m Mongo) UpdateMany(collectionName string, filter interface{}, update interface{}) (*mongo.UpdateResult, error)
UpdateMany update many documents.
type PathConfigModel ¶
PathConfigModel is the authority path section in `config.toml`;
type PinYinModel ¶
type PinYinModel struct { // TotalPinYin is the total pinyin. TotalPinYin string // FirstPinYin is the first letter of pinyin. FirstPinYin string }
PinYinModel is the returned pinyin model.
func ConvertToPinYin ¶
func ConvertToPinYin(text string) (model PinYinModel)
ConvertToPinYin convert Chinese character to Chinese pinyin which is convenient to search using keywords.
type RemoteConfigModel ¶
type RemoteConfigModel struct { Enabled bool `toml:"enabled"` WebSocketPort int `toml:"web_socket_port"` }
RemoteConfigModel is the remote config section in `config.toml`;
type ServerConfigModel ¶
type ServerConfigModel struct {
Port string `toml:"port"`
}
ServerConfigModel is the server config section in `config.toml`;
type UploadConfigModel ¶
type UploadConfigModel struct {
MaxSize int64 `toml:"max_size"`
}
UploadConfigModel is the upload config section in `config.toml`;