本文整理汇总了Golang中github.com/gosimple/slug.Make函数的典型用法代码示例。如果您正苦于以下问题:Golang Make函数的具体用法?Golang Make怎么用?Golang Make使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Make函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
}
}
示例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
})
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
}
}
示例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())
}
示例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
}
示例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 {
//.........这里部分代码省略.........
示例13: UpdateSlug
// UpdateSlug updates the slug
func (dash *Dashboard) UpdateSlug() {
title := strings.ToLower(dash.Data.Get("title").MustString())
dash.Slug = slug.Make(title)
}
示例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)
//.........这里部分代码省略.........
示例15: UpdateSlug
// UpdateSlug updates the slug
func (dash *Dashboard) UpdateSlug() {
title := strings.ToLower(dash.Data["title"].(string))
dash.Slug = slug.Make(title)
}