• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang core.Core类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cfstras/cfmedias/core.Core的典型用法代码示例。如果您正苦于以下问题:Golang Core类的具体用法?Golang Core怎么用?Golang Core使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Core类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Start

func (s *Sync) Start(c core.Core, db *db.DB) {
	s.core = c
	s.db = db
	s.config = config.Current.Plugins[PluginName].(*Config)

	c.RegisterCommand(core.Command{[]string{"sync", "s"},
		"Syncs media with a device or folder. By default, lossles files are converted to MP3 V0.",
		map[string]string{
			"path":    "Target path",
			"convert": "boolean, default is true"},
		core.AuthAdmin,
		func(ctx core.CommandContext) core.Result {
			args := ctx.Args
			var err error
			pathS, err := util.GetArg(args, "path", true, err)
			convertS, err := util.GetArg(args, "convert", true, err)
			doConvert, err := util.CastBool(convertS, err)
			if err != nil {
				return core.ResultByError(err)
			}
			convert := true
			if doConvert != nil {
				convert = *doConvert
			}
			return core.ResultByError(s.Sync(*pathS, convert))
		}})
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:27,代码来源:main.go


示例2: initList

func (db *DB) initList(c core.Core) {
	c.RegisterCommand(core.Command{
		[]string{"list", "ls"},
		"Searches and lists items from the database",
		map[string]string{
			"text":  "(Optional) Search string for full text search",
			"query": "(Optional) Input for SQL-ish query",
			"tags":  "(Optional) Comma-separated list of tags to include",
		},
		core.AuthGuest,
		db.list})
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:12,代码来源:list.go


示例3: initLogic

func (db *DB) initLogic(c core.Core) {
	c.RegisterCommand(core.Command{
		[]string{"trackplayed"},
		"Inserts a track playback into the database statistics",
		map[string]string{
			"title":         "Title",
			"artist":        "Artist",
			"album":         "Album",
			"album_artist":  "Album Artist",
			"length":        "Track length in ms",
			"date":          "Time the listening occurred, as Unix timestamp",
			"length_played": "The time the track was listened to (when fully played: length) in ms",
			"scrobbled":     "Whether the track was scrobbled to last.fm/libre.fm"},
		core.AuthUser,
		db.TrackPlayed})
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:16,代码来源:logic.go


示例4: initStats

func (d *DB) initStats(c core.Core) {
	c.RegisterCommand(core.Command{
		[]string{"stats"},
		"Prints some statistics about the database",
		map[string]string{},
		core.AuthUser,
		func(_ core.CommandContext) core.Result {
			res := map[string]interface{}{
				"items_total":      d.TitlesTotal(),
				"folders_total":    d.FoldersTotal(),
				"items_per_folder": d.AvgFilesPerFolder(),
			}
			//TODO more stats
			//TODO stats per user level
			return core.Result{Status: core.StatusOK, Result: res}
		}})
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:17,代码来源:stats.go


示例5: Open

func (d *DB) Open(c core.Core) error {
	if d.open {
		return errrs.New("DB is already opened!")
	}
	d.c = c

	var err error
	file := config.Current.DbFile

	d.db, err = gorm.Open("sqlite3", file)
	if err != nil {
		return err
	}
	d.open = true

	d.db.LogMode(true)
	if err := d.checkTables(); err != nil {
		return err
	}

	err = d.checkSanity()
	if err != nil {
		//TODO what now?
		return err
	}

	d.initStats(c)
	d.initLogic(c) // hear the difference?
	d.initLogin(c) // it's subtle but it could save your life
	d.initList(c)

	c.RegisterCommand(core.Command{
		[]string{"rescan"},
		"Refreshes the database by re-scanning the media folder.",
		map[string]string{},
		core.AuthAdmin,
		func(_ core.CommandContext) core.Result {
			go d.Update()
			return core.ResultOK
		}})

	return nil
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:43,代码来源:db.go


示例6: Start

func (a *AS) Start(c core.Core, d *db.DB) {
	a.db = d

	//TODO get base url
	baseURL := "http://localhost/api/"
	a.nowPlayingURL = baseURL + "as_nowplaying"
	a.submissionURL = baseURL + "as_scrobble"

	c.RegisterCommand(core.Command{
		[]string{"audioscrobbler", "as"},
		`Interface for clients using the Last.fm Submissions Protocol v1.2.1.
In your favourite scrobbler, use this as handshake URL:
http://cfmedias-server-ip/api/audioscrobbler/?hs=true
See also http://www.last.fm/api/submissions.`,
		map[string]string{
			"hs": "hs=true marks a handshake request. requires p, c, v, u, t, a.",
			"p":  "must be 1.2.1",
			"c":  "identifier for the client software",
			"v":  "version of the client software",
			"u":  "username",
			"t":  "timestamp of the request",
			"a":  "authentication message: md5(md5(auth_token) + timestamp)",
			"__response": `The server will respond with:
OK
<session ID>
<url to be used for a now-playing request>
<url to be used for a submission request>

or one of these:
BANNED: Your client is doing bad things and is therefore banned.
BADAUTH: Authentication details are incorrect.
BADTIME: Time difference between server and client time too high.
 Correct your system clock.
FAILED <reason>: Your request failed for the specified reason.`},
		core.AuthGuest,
		a.LoginAS})
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:37,代码来源:as.go


示例7: initLogin

func (db *DB) initLogin(c core.Core) {
	c.RegisterCommand(core.Command{
		[]string{"create_user"},
		"Creates a user in the database",
		map[string]string{
			"name":  "Username",
			"email": "E-Mail",
			"auth_level": fmt.Sprintf("User Rank: Guest(%d), User(%d), "+
				"Admin(%d), Root(%d)", core.AuthGuest, core.AuthUser,
				core.AuthAdmin, core.AuthRoot),
			"password": "Password"},
		core.AuthAdmin,
		func(ctx core.CommandContext) core.Result {
			args := ctx.Args
			var err error
			name, err := util.GetArg(args, "name", true, err)
			email, err := util.GetArg(args, "email", true, err)
			authLevelS, err := util.GetArg(args, "auth_level", true, err)
			password, err := util.GetArg(args, "password", true, err)

			authLevelI, err := util.CastUint(authLevelS, err)

			if err != nil {
				return core.Result{Status: core.StatusError, Error: err}
			}
			authLevel := core.AuthLevel(*authLevelI)

			if authLevel >= ctx.AuthLevel {
				return core.ResultByError(errrs.New("You cannot create a user" +
					" with that level!"))
			}

			user, err := db.CreateUser(*name, *email, authLevel, *password)
			if err == nil {
				return core.Result{Status: core.StatusOK, Result: user}
			}
			return core.Result{Status: core.StatusError, Error: err}
		}})

	c.RegisterCommand(core.Command{
		[]string{"login"},
		"Logs in with user/password and returns the auth token",
		map[string]string{
			"name":     "Username",
			"password": "Password"},
		core.AuthGuest,
		func(ctx core.CommandContext) core.Result {
			args := ctx.Args
			var err error
			name, err := util.GetArg(args, "name", true, err)
			password, err := util.GetArg(args, "password", true, err)

			if err != nil {
				return core.ResultByError(err)
			}

			success, authToken, err := db.Login(*name, *password)
			if err == nil && success {
				return core.Result{Status: core.StatusOK,
					Result: map[string]string{"auth_token": authToken}}
			}
			if err == nil {
				return core.Result{Status: core.StatusError,
					Error: errrs.New("Wrong username or password")}
			}
			return core.Result{Status: core.StatusError, Error: err}
		}})

	c.RegisterCommand(core.Command{
		[]string{"change_authtoken", "logout"},
		`Changes the authentication token of the user, thereby logging out all
clients`,
		map[string]string{
			"name": `(Optional) username of the user to log out. Leave empty to
use current user`,
		},
		core.AuthUser,
		func(ctx core.CommandContext) core.Result {
			args := ctx.Args
			var err error
			name, err := util.GetArg(args, "name", false, err)
			if err != nil {
				return core.ResultByError(err)
			}
			var user *User
			if name != nil {
				if ctx.AuthLevel < core.AuthAdmin {
					return core.ResultByError(core.ErrorNotAllowed)
				}
				user, err = db.GetUserByName(*name)
			} else {
				if ctx.UserId == nil {
					return core.ResultByError(core.ErrorNotLoggedIn)
				}
				user, err = db.GetUser(*ctx.UserId)
			}
			if user == nil {
				return core.ResultByError(core.ErrorUserNotFound)
			}
			_, err = db.ChangeAuthToken(user)
//.........这里部分代码省略.........
开发者ID:cfstras,项目名称:cfmedias,代码行数:101,代码来源:login.go



注:本文中的github.com/cfstras/cfmedias/core.Core类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cache.Get函数代码示例发布时间:2022-05-23
下一篇:
Golang err.Panic函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap