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

Golang slug.Make函数代码示例

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

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



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

示例1: ContainerHost

// ContainerHost slugifies the container's name and append docker
func (expose Expose) ContainerHost(name string) string {
	if composeRe.MatchString(name) {
		parts := composeRe.FindStringSubmatch(name)
		name = slug.Make(parts[2]) + parts[3] + "." + slug.Make(parts[1])
	} else {
		name = slug.Make(name)
	}
	return fmt.Sprintf("%s.docker", name)
}
开发者ID:AerisCloud,项目名称:docker-expose,代码行数:10,代码来源:expose.go


示例2: initApp

func (app *AppPlugin) initApp() {
	app.initFrontendPlugin()

	// check if we have child panels
	for _, panel := range Panels {
		if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
			panel.setPathsBasedOnApp(app)
			app.FoundChildPlugins = append(app.FoundChildPlugins, &PluginInclude{
				Name: panel.Name,
				Id:   panel.Id,
				Type: panel.Type,
			})
		}
	}

	// check if we have child datasources
	for _, ds := range DataSources {
		if strings.HasPrefix(ds.PluginDir, app.PluginDir) {
			ds.setPathsBasedOnApp(app)
			app.FoundChildPlugins = append(app.FoundChildPlugins, &PluginInclude{
				Name: ds.Name,
				Id:   ds.Id,
				Type: ds.Type,
			})
		}
	}

	// slugify pages
	for _, page := range app.Pages {
		if page.Slug == "" {
			page.Slug = slug.Make(page.Name)
		}
	}
}
开发者ID:jonny-improbable,项目名称:grafana,代码行数:34,代码来源:app_plugin.go


示例3: AddSystem

func AddSystem(cmd *m.AddSystemsCommand) error {
	return inTransaction(func(sess *xorm.Session) error {
		// check if service exists
		var err error
		for _, systemName := range cmd.SystemsName {
			if res, err := sess.Query("SELECT 1 from systems WHERE systems_name=? and org_id=?", systemName, cmd.OrgId); err != nil {
				return err
			} else if len(res) == 1 {
				return m.ErrSystemAlreadyAdded
			}

			entity := m.Systems{
				OrgId:       cmd.OrgId,
				SystemsName: systemName,
				Slug:        slug.Make(systemName),
			}

			_, err = sess.Insert(&entity)

			apiEntity := m.AddApiKeyCommand{}
			apiEntity.OrgId = cmd.OrgId
			apiEntity.Name = strconv.FormatInt(entity.Id, 16)
			apiEntity.Role = m.ROLE_ADMIN
			newKeyInfo := apikeygen.New(apiEntity.OrgId, apiEntity.Name)
			apiEntity.Key = newKeyInfo.ClientSecret
			err = AddApiKey(&apiEntity)
		}
		return err
	})
}
开发者ID:wangy1931,项目名称:grafana,代码行数:30,代码来源:systems.go


示例4: Load

func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
	if err := decoder.Decode(&app); err != nil {
		return err
	}

	if app.Css != nil {
		app.Css.Dark = evalRelativePluginUrlPath(app.Css.Dark, app.Id)
		app.Css.Light = evalRelativePluginUrlPath(app.Css.Light, app.Id)
	}

	app.PluginDir = pluginDir
	app.initFrontendPlugin()

	// check if we have child panels
	for _, panel := range Panels {
		if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
			panel.IncludedInAppId = app.Id
			app.Includes = append(app.Includes, &AppIncludeInfo{
				Name: panel.Name,
				Id:   panel.Id,
				Type: panel.Type,
			})
		}
	}

	for _, page := range app.Pages {
		if page.Slug == "" {
			page.Slug = slug.Make(page.Name)
		}
	}

	Apps[app.Id] = app
	return nil
}
开发者ID:kaefik,项目名称:grafana,代码行数:34,代码来源:app_plugin.go


示例5: generatePosts

func (g StaticBlogGenerator) generatePosts() error {
	for _, post := range g.posts {
		err := g.generatePage(g.postTemplate, slug.Make(post.Title)+".html", post)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:mirovarga,项目名称:litepub,代码行数:10,代码来源:generators.go


示例6: MonitorsMetrics

func (n *Ns1) MonitorsMetrics(client *Client, mts []plugin.MetricType) ([]plugin.MetricType, error) {
	metrics := make([]plugin.MetricType, 0)
	conf := mts[0].Config().Table()
	jobId, ok := conf["jobId"]
	if !ok || jobId.(ctypes.ConfigValueStr).Value == "" {
		LogError("jobId missing from config.")
		return metrics, nil
	}
	jobName, ok := conf["jobName"]
	if !ok || jobName.(ctypes.ConfigValueStr).Value == "" {
		LogError("jobName missing from config.")
		return metrics, nil
	}

	jSlug := slug.Make(jobName.(ctypes.ConfigValueStr).Value)

	j, err := client.MonitoringJobById(jobId.(ctypes.ConfigValueStr).Value)
	if err != nil {
		LogError("failed to query for job.", err)
		return nil, err
	}

	for region, status := range j.Status {
		data, ok := statusMap[status.Status]
		if !ok {
			return nil, fmt.Errorf("Unknown monitor status")
		}

		metrics = append(metrics, plugin.MetricType{
			Data_:      data,
			Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", jSlug, region, "state"),
			Timestamp_: time.Now(),
			Version_:   mts[0].Version(),
		})

	}

	jobMetrics, err := client.MonitoringMetics(j.Id)
	if err != nil {
		return nil, err
	}
	for _, jm := range jobMetrics {
		for stat, m := range jm.Metrics {
			metrics = append(metrics, plugin.MetricType{
				Data_:      m.Avg,
				Namespace_: core.NewNamespace("raintank", "apps", "ns1", "monitoring", jSlug, jm.Region, stat),
				Timestamp_: time.Now(),
				Version_:   mts[0].Version(),
			})
		}
	}

	return metrics, nil
}
开发者ID:ChihChaoChang,项目名称:raintank-apps,代码行数:54,代码来源:ns1.go


示例7: generateTags

func (g StaticBlogGenerator) generateTags() error {
	for tag, posts := range g.postsByTag {
		err := g.generatePage(g.tagTemplate,
			filepath.Join("tags", slug.Make(tag)+".html"), struct {
				Name  string
				Posts []domain.Post
			}{tag, posts})
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:mirovarga,项目名称:litepub,代码行数:14,代码来源:generators.go


示例8: writePost

func (r FSBlogRepository) writePost(id string, post domain.Post) error {
	path := filepath.Join(r.dir, id, postsDir)
	if post.Draft {
		path = filepath.Join(path, draftDir)
	}
	path = filepath.Join(path, slug.Make(post.Title)+".md")

	var data string
	if len(post.Tags) == 0 {
		data = fmt.Sprintf("# %s\n\n*%s*\n\n%s\n", post.Title,
			post.Written.Format("Jan 2, 2006"), post.Content)
	} else {
		data = fmt.Sprintf("# %s\n\n*%s*\n\n*%s*\n\n%s\n", post.Title,
			post.Written.Format("Jan 2, 2006"), strings.Join(post.Tags, ", "),
			post.Content)
	}

	return ioutil.WriteFile(path, []byte(data), 0600)
}
开发者ID:mirovarga,项目名称:litepub,代码行数:19,代码来源:repositories.go


示例9: initApp

func (app *AppPlugin) initApp() {
	app.initFrontendPlugin()

	// check if we have child panels
	for _, panel := range Panels {
		if strings.HasPrefix(panel.PluginDir, app.PluginDir) {
			panel.setPathsBasedOnApp(app)
			app.FoundChildPlugins = append(app.FoundChildPlugins, &PluginInclude{
				Name: panel.Name,
				Id:   panel.Id,
				Type: panel.Type,
			})
		}
	}

	// check if we have child datasources
	for _, ds := range DataSources {
		if strings.HasPrefix(ds.PluginDir, app.PluginDir) {
			ds.setPathsBasedOnApp(app)
			app.FoundChildPlugins = append(app.FoundChildPlugins, &PluginInclude{
				Name: ds.Name,
				Id:   ds.Id,
				Type: ds.Type,
			})
		}
	}

	app.DefaultNavUrl = setting.AppSubUrl + "/plugins/" + app.Id + "/edit"

	// slugify pages
	for _, include := range app.Includes {
		if include.Slug == "" {
			include.Slug = slug.Make(include.Name)
		}
		if include.Type == "page" && include.DefaultNav {
			app.DefaultNavUrl = setting.AppSubUrl + "/plugins/" + app.Id + "/page/" + include.Slug
		}
		if include.Type == "dashboard" && include.DefaultNav {
			app.DefaultNavUrl = setting.AppSubUrl + "/dashboard/db/" + include.Slug
		}
	}
}
开发者ID:volter,项目名称:grafana,代码行数:42,代码来源:app_plugin.go


示例10: Create

func (a *Article) Create() error {
	if a == nil {
		return apierror.NewServerError("article not instanced")
	}

	if a.Slug == "" {
		a.Slug = slug.Make(a.Title)
	}

	if bson.IsObjectIdHex(a.Slug) {
		return apierror.NewBadRequest("slug cannot be a ObjectId")
	}

	a.CreatedAt = time.Now()

	// To prevent duplicates on the slug, we'll retry the insert() up to 10 times
	originalSlug := a.Slug
	var err error
	for i := 0; i < 10; i++ {
		a.ID = bson.NewObjectId()
		err = Query().Insert(a)

		if err != nil {
			// In case of duplicate we'll add "-X" at the end of the slug, where X is
			// a number
			a.Slug = fmt.Sprintf("%s-%d", originalSlug, i)

			if mgo.IsDup(err) == false {
				return apierror.NewServerError(err.Error())
			}
		} else {
			// everything went well
			return nil
		}
	}

	// after 10 try we just return an error
	return apierror.NewConflict(err.Error())
}
开发者ID:Nivl,项目名称:api.melvin.la,代码行数:39,代码来源:model_article.go


示例11: ZoneMetrics

func (n *Ns1) ZoneMetrics(client *Client, mts []plugin.MetricType) ([]plugin.MetricType, error) {
	metrics := make([]plugin.MetricType, 0)
	conf := mts[0].Config().Table()
	zone, ok := conf["zone"]
	if !ok || zone.(ctypes.ConfigValueStr).Value == "" {
		LogError("zone missing from config.")
		return metrics, nil
	}
	zSlug := slug.Make(zone.(ctypes.ConfigValueStr).Value)

	qps, err := client.Qps(zone.(ctypes.ConfigValueStr).Value)
	if err != nil {
		return nil, err
	}
	metrics = append(metrics, plugin.MetricType{
		Data_:      qps.Qps,
		Namespace_: core.NewNamespace("raintank", "apps", "ns1", "zones", zSlug, "qps"),
		Timestamp_: time.Now(),
		Version_:   mts[0].Version(),
	})

	return metrics, nil
}
开发者ID:ChihChaoChang,项目名称:raintank-apps,代码行数:23,代码来源:ns1.go


示例12: gitStats

func gitStats(accessToken string, mts []plugin.MetricType) ([]plugin.MetricType, error) {
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: accessToken},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)
	client := github.NewClient(tc)
	collectionTime := time.Now()
	repos := make(map[string]map[string]map[string]int)
	users := make(map[string]map[string]int)

	userRepos := make(map[string]struct{})
	authUser := ""
	useRepo := ""
	conf := mts[0].Config().Table()
	confUser, ok := conf["user"]
	if ok && confUser.(ctypes.ConfigValueStr).Value != "" {
		authUser = confUser.(ctypes.ConfigValueStr).Value
	}
	confRepo, ok := conf["repo"]
	if ok && confRepo.(ctypes.ConfigValueStr).Value != "" {
		useRepo = confRepo.(ctypes.ConfigValueStr).Value
	}

	metrics := make([]plugin.MetricType, 0)

	for _, m := range mts {
		ns := m.Namespace().Strings()
		fmt.Printf("getting %s\n", m.Namespace().String())
		switch ns[3] {
		case "repo":
			user := ns[4]
			repo := ns[5]
			stat := ns[6]

			if user == "*" {
				//need to get user
				if authUser == "" {
					gitUser, _, err := client.Users.Get("")
					if err != nil {
						LogError("failed to get authenticated user.", err)
						return nil, err
					}
					stats, err := userStats(gitUser, client)
					if err != nil {
						LogError("failed to get stats from user object.", err)
						return nil, err
					}
					users[*gitUser.Login] = stats
					authUser = *gitUser.Login
				}
				user = authUser
			}
			if repo == "*" && useRepo == "" {
				// get list of all repos owned by the user.
				if _, ok := userRepos[user]; !ok {
					opt := &github.RepositoryListOptions{Type: "owner"}
					repoList, _, err := client.Repositories.List(user, opt)
					if err != nil {
						LogError("failed to get repos owned by user.", err)
						return nil, err
					}
					userRepos[user] = struct{}{}
					if _, ok := repos[user]; !ok {
						repos[user] = make(map[string]map[string]int)
					}
					for _, r := range repoList {
						stats, err := repoStats(r)
						if err != nil {
							LogError("failed to get stats from repo object.", err)
							return nil, err
						}
						repoSlug := slug.Make(*r.Name)
						repos[user][repoSlug] = stats
					}
				}
				for repo, stats := range repos[user] {
					mt := plugin.MetricType{
						Data_:      stats[stat],
						Namespace_: core.NewNamespace("raintank", "apps", "gitstats", "repo", user, repo, stat),
						Timestamp_: collectionTime,
						Version_:   m.Version(),
					}
					metrics = append(metrics, mt)
				}
			} else {
				if repo == "*" {
					repo = useRepo
				}
				repoSlug := slug.Make(repo)
				if _, ok := repos[user]; !ok {
					repos[user] = make(map[string]map[string]int)
				}
				if _, ok := repos[user][repoSlug]; !ok {
					r, _, err := client.Repositories.Get(user, repo)
					if err != nil {
						LogError("failed to user repos.", err)
						return nil, err
					}
					stats, err := repoStats(r)
					if err != nil {
//.........这里部分代码省略.........
开发者ID:ChihChaoChang,项目名称:raintank-apps,代码行数:101,代码来源:gitstats.go


示例13: UpdateSlug

// UpdateSlug updates the slug
func (dash *Dashboard) UpdateSlug() {
	title := strings.ToLower(dash.Data.Get("title").MustString())
	dash.Slug = slug.Make(title)
}
开发者ID:CamJN,项目名称:grafana,代码行数:5,代码来源:dashboards.go


示例14: TestDashboardDataAccess

func TestDashboardDataAccess(t *testing.T) {

	Convey("Testing DB", t, func() {
		InitTestDB(t)

		Convey("Given saved dashboard", func() {
			savedDash := insertTestDashboard("test dash 23", 1, "prod", "webapp")
			insertTestDashboard("test dash 45", 1, "prod")
			insertTestDashboard("test dash 67", 1, "prod", "webapp")

			Convey("Should return dashboard model", func() {
				So(savedDash.Title, ShouldEqual, "test dash 23")
				So(savedDash.Slug, ShouldEqual, "test-dash-23")
				So(savedDash.Id, ShouldNotEqual, 0)
			})

			Convey("Should be able to get dashboard", func() {
				query := m.GetDashboardQuery{
					Slug:  "test-dash-23",
					OrgId: 1,
				}

				err := GetDashboard(&query)
				So(err, ShouldBeNil)

				So(query.Result.Title, ShouldEqual, "test dash 23")
				So(query.Result.Slug, ShouldEqual, "test-dash-23")
			})

			Convey("Should be able to delete dashboard", func() {
				insertTestDashboard("delete me", 1, "delete this")

				dashboardSlug := slug.Make("delete me")

				err := DeleteDashboard(&m.DeleteDashboardCommand{
					Slug:  dashboardSlug,
					OrgId: 1,
				})

				So(err, ShouldBeNil)
			})

			Convey("Should return error if no dashboard is updated", func() {
				cmd := m.SaveDashboardCommand{
					OrgId:     1,
					Overwrite: true,
					Dashboard: simplejson.NewFromAny(map[string]interface{}{
						"id":    float64(123412321),
						"title": "Expect error",
						"tags":  []interface{}{},
					}),
				}

				err := SaveDashboard(&cmd)
				So(err, ShouldNotBeNil)
			})

			Convey("Should not be able to overwrite dashboard in another org", func() {
				query := m.GetDashboardQuery{Slug: "test-dash-23", OrgId: 1}
				GetDashboard(&query)

				cmd := m.SaveDashboardCommand{
					OrgId:     2,
					Overwrite: true,
					Dashboard: simplejson.NewFromAny(map[string]interface{}{
						"id":    float64(query.Result.Id),
						"title": "Expect error",
						"tags":  []interface{}{},
					}),
				}

				err := SaveDashboard(&cmd)
				So(err, ShouldNotBeNil)
			})

			Convey("Should be able to search for dashboard", func() {
				query := search.FindPersistedDashboardsQuery{
					Title: "test dash 23",
					OrgId: 1,
				}

				err := SearchDashboards(&query)
				So(err, ShouldBeNil)

				So(len(query.Result), ShouldEqual, 1)
				hit := query.Result[0]
				So(len(hit.Tags), ShouldEqual, 2)
			})

			Convey("Should be able to search for dashboard by dashboard ids", func() {
				Convey("should be able to find two dashboards by id", func() {
					query := search.FindPersistedDashboardsQuery{
						DashboardIds: []int{1, 2},
						OrgId:        1,
					}

					err := SearchDashboards(&query)
					So(err, ShouldBeNil)

					So(len(query.Result), ShouldEqual, 2)
//.........这里部分代码省略.........
开发者ID:roman-vynar,项目名称:grafana,代码行数:101,代码来源:dashboard_test.go


示例15: UpdateSlug

// UpdateSlug updates the slug
func (dash *Dashboard) UpdateSlug() {
	title := strings.ToLower(dash.Data["title"].(string))
	dash.Slug = slug.Make(title)
}
开发者ID:gbrian,项目名称:grafana,代码行数:5,代码来源:dashboards.go


示例16: autoGenSlug

func (n *News) autoGenSlug() {
	n.Slug = slug.Make(n.Title)
}
开发者ID:dyzajash,项目名称:TB_cms_old,代码行数:3,代码来源:news.go


示例17: slugify

func slugify(str string) string {
	return slug.Make(str)
}
开发者ID:mirovarga,项目名称:litepub,代码行数:3,代码来源:generators.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang store.Item类代码示例发布时间:2022-05-23
下一篇:
Golang to.String函数代码示例发布时间: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