本文整理匯總了Golang中github.com/extemporalgenome/slug.Slug函數的典型用法代碼示例。如果您正苦於以下問題:Golang Slug函數的具體用法?Golang Slug怎麽用?Golang Slug使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Slug函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: exportAliases
func exportAliases() {
var (
repositories *Repositories
environments *Environments
environment *Environment
err error
)
if repositories, err = bot.GetRepositories(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
if environments, err = bot.GetEnvironments(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
mappedEnvironments := make(map[int][]*Environment)
for _, environment = range environments.Entries {
mappedEnvironments[environment.RepositoryId] = append(mappedEnvironments[environment.RepositoryId], environment)
}
fmt.Printf("[aliases]\n")
for _, repository := range repositories.Entries {
fmt.Printf("# %s\n", repository.Title)
fmt.Printf("%s = %d\n", slug.Slug(repository.Title), repository.Id)
for _, environment := range mappedEnvironments[repository.Id] {
fmt.Printf("\t%s-%s = %d\n", slug.Slug(repository.Title), slug.Slug(environment.Name), environment.Id)
}
}
}
示例2: GetNodes
// GetNodes returns the D3-compatible nodes by rta analysis
func GetNodes(prog *ssa.Program) ([]node.Node, error) {
main, err := mainPackage(prog, false)
if err != nil {
return nil, err
}
roots := []*ssa.Function{
main.Func("init"),
main.Func("main"),
}
added := make(map[string]struct{})
extraImports := make(map[string][]string)
var nodes []node.Node
callgraph := rta.Analyze(roots, true)
callgraph.CallGraph.DeleteSyntheticNodes()
for _, bar := range callgraph.CallGraph.Nodes {
_, ok := added[bar.Func.Package().String()]
if !ok {
for _, edge := range bar.Out {
if extraImports[edge.Callee.Func.Package().String()] == nil {
extraImports[edge.Callee.Func.Package().String()] = make([]string, 0)
}
extraImports[edge.Callee.Func.Package().String()] = append(extraImports[edge.Callee.Func.Package().String()], strings.TrimPrefix(slug.Slug(bar.Func.Package().String()), "package-"))
}
added[bar.Func.Package().String()] = struct{}{}
}
}
added = make(map[string]struct{})
for _, bar := range callgraph.CallGraph.Nodes {
_, ok := added[bar.Func.Package().String()]
if !ok {
var imports []string
for _, edge := range bar.In {
imports = append(imports, strings.TrimPrefix(slug.Slug(edge.Caller.Func.Package().String()), "package-"))
}
imports = append(imports, extraImports[bar.Func.Package().String()]...)
nodes = append(nodes, node.Node{Name: strings.TrimPrefix(slug.Slug(bar.Func.Package().String()), "package-"), Imports: imports, Size: len(imports) * 100})
added[bar.Func.Package().String()] = struct{}{}
}
}
return nodes, nil
}
示例3: ProcessContent
func (p *Page) ProcessContent() {
content := string(p.Content)
titles := titlePattern.FindAllStringSubmatch(content, -1)
for _, title := range titles {
if p.Titles == nil {
p.Titles = make(map[int][]anchor)
}
if len(title) == 3 {
if level, _ := strconv.Atoi(title[1]); level > 0 {
ll := level - 1
text := title[2]
id := slug.Slug(text)
if id == "" {
id = fmt.Sprintf("%05d", level)
}
if p.Titles[ll] == nil {
p.Titles[ll] = []anchor{}
}
r := fmt.Sprintf(`<h%d><a href="#%s" name="%s">%s</a></h%d>`, level, id, id, text, level)
p.Titles[ll] = append(p.Titles[ll], anchor{Text: text, URL: "#" + id})
content = strings.Replace(content, title[0], r, 1)
}
}
}
p.Content = template.HTML(content)
}
示例4: fillAndValidate
// fillAndValidate tag
func (model *Tag) fillAndValidate(payload Tag, isEdit bool) (err error) {
if !isEdit {
// new
} else {
model.ID = payload.ID
}
model.Name = strings.TrimSpace(payload.Name)
model.Description = strings.TrimSpace(payload.Description)
model.Slug = strings.TrimSpace(payload.Slug)
if model.Slug == "" || !slug.IsSlugAscii(model.Slug) {
// generate slug
model.Slug = slug.Slug(model.Name)
}
model.Image = strings.TrimSpace(payload.Image)
model.IsVisible = payload.IsVisible
model.ParentID = payload.ParentID
model.MetaTitle = payload.MetaTitle
if model.MetaTitle == "" {
model.MetaTitle = model.Name
}
model.MetaDescription = payload.MetaDescription
if model.MetaDescription == "" {
model.MetaDescription = model.Description
}
model.UpdatedBy = payload.UpdatedBy
return
}
示例5: checkAndCreateCategories
func checkAndCreateCategories(db DB) {
for i, categoryName := range categoryList {
categorySlug := slug.Slug(categoryName)
count, err := db.SelectInt("select count(*) from category where categoryslug=?", categorySlug)
if err != nil {
log.Printf("Error searching for the category with categorySlug %s\n", categorySlug)
log.Println("Stopping the creation of categories")
return
}
if count == 0 {
category := &Category{
CategoryId: uniuri.NewLen(20),
CategoryName: categoryName,
CategorySlug: categorySlug,
LikeCount: 0,
}
if i == 0 { // "Sem Categoria" is my default category
category.CategoryId = "default"
}
err := db.Insert(category)
if err != nil {
log.Printf("Error when creating the category %s. %s\n", category.CategoryName, err)
} else {
log.Printf("Category %s created!\n", category.CategoryName)
}
}
}
}
示例6: parseExamples
func parseExamples() []*Example {
exampleNames := readLines("examples.txt")
examples := make([]*Example, 0)
for _, exampleName := range exampleNames {
if (exampleName != "") && !strings.HasPrefix(exampleName, "#") {
example := Example{Name: exampleName}
exampleId := slug.Slug(exampleName)
example.Id = exampleId
example.Segs = make([][]*Seg, 0)
sourcePaths := mustGlob("examples/" + exampleId + "/*")
for _, sourcePath := range sourcePaths {
if strings.HasSuffix(sourcePath, ".hash") {
example.GoCodeHash, example.UrlHash = parseHashFile(sourcePath)
} else {
sourceSegs, filecontents := parseAndRenderSegs(sourcePath)
if filecontents != "" {
example.GoCode = filecontents
}
example.Segs = append(example.Segs, sourceSegs)
}
}
newCodeHash := sha1Sum(example.GoCode)
if example.GoCodeHash != newCodeHash {
example.UrlHash = resetUrlHashFile(newCodeHash, example.GoCode, "examples/"+example.Id+"/"+example.Id+".hash")
}
examples = append(examples, &example)
}
}
for i, example := range examples {
if i < (len(examples) - 1) {
example.NextExample = examples[i+1]
}
}
return examples
}
示例7: CreateContent
func CreateContent(db DB, user *User, url *Url, img *Image, content *Content) (*Content, error) {
contentId := uniuri.NewLen(20)
u, err := db.Get(Content{}, contentId)
for err == nil && u != nil {
contentId := uniuri.NewLen(20)
u, err = db.Get(Content{}, contentId)
}
if err != nil {
return nil, err
}
s := slug.Slug(content.Title)
// Let's check if this slug already exists,
// if existis, we will increment a sulfix to it
newSlug := s
increment := 1
count, err := db.SelectInt("select count(*) from content where slug=?", newSlug)
for err == nil && count != 0 {
increment += 1
newSlug = fmt.Sprintf("%s-%d", s, increment)
count, err = db.SelectInt("select count(*) from content where slug=?", newSlug)
}
log.Printf("SLUG: %s, inc: %d, count: %d\n", newSlug, increment, count)
if err != nil {
return nil, err
}
newContent := &Content{
ContentId: contentId,
UrlId: url.UrlId,
CategoryId: "default", // First category will be "Sem categoria"
Title: content.Title,
Slug: newSlug,
Description: content.Description,
Host: content.Host,
UserId: user.UserId,
ImageId: "default", // We will check the if there is an image below
LikeCount: 0,
Creation: time.Now(),
LastUpdate: time.Now(),
Deleted: false,
}
if img != nil {
newContent.ImageId = img.ImageId
}
err = db.Insert(newContent)
if err != nil {
return nil, err
}
return newContent, nil
}
示例8: fillAndValidate
func (model *Post) fillAndValidate(payload PostPayload, isEdit bool) (err error) {
body := strings.TrimSpace(payload.Body)
if !isEdit {
// new
// uuid
model.UUID = uuid.NewV4().String()
model.CreatedBy = payload.AuthorID
// generate excerpt
bodyLength := len(body)
// get # of characters to generate excerpt
// this is usually taken from settings
// but we'll hard code it for now
excerptChars := 200
if bodyLength < excerptChars {
excerptChars = bodyLength
}
model.Excerpt = body[:excerptChars]
} else {
model.ID = payload.ID
model.Excerpt = strings.TrimSpace(payload.Excerpt)
}
model.Title = strings.TrimSpace(payload.Title)
model.Slug = strings.TrimSpace(payload.Slug)
if model.Slug == "" || !slug.IsSlugAscii(model.Slug) {
// generate slug
model.Slug = slug.Slug(model.Title)
}
model.Subtitle = strings.TrimSpace(payload.Subtitle)
model.Body = body
model.Featured = payload.Featured
model.Image = strings.TrimSpace(payload.Image)
model.AuthorID = payload.AuthorID
model.UpdatedBy = payload.AuthorID
model.MetaTitle = strings.TrimSpace(payload.MetaTitle)
model.MetaDescription = strings.TrimSpace(payload.MetaDescription)
if model.Status == "published" {
// parse published_at from format: MM-DD-YYYY hh:mm
publishedAt, err2 := utils.ParseDate(LONGFORM, payload.PublishedAt)
if err2 != nil {
err = err2
return
}
model.PublishedAt = pq.NullTime{
Time: publishedAt,
Valid: true,
}
}
return
}
示例9: BeforeUpdate
func (u *Group) BeforeUpdate(tx *gorm.DB) (err error) {
var count int
tx.Model(u).Where("name = ?", u.Name).Count(&count)
if count > 1 {
err = errors.New("Conflicting Name!")
return
}
u.Slug = slug.Slug(u.Name)
return
}
示例10: BeforeCreate
func (u *Media) BeforeCreate(tx *gorm.DB) (err error) {
var count int
tx.Model(u).Where("name = ?", u.Name).Count(&count)
if count > 0 {
err = errors.New("Media exists!")
return
}
u.Slug = slug.Slug(u.Name)
return
}
示例11: GetNodes
// GetNodes returns the D3-compatible nodes by cha analysis -
// notably, works without a main()
func GetNodes(prog *ssa.Program) ([]node.Node, error) {
added := make(map[string]struct{})
extraImports := make(map[string][]string)
var nodes []node.Node
callgraph := cha.CallGraph(prog)
callgraph.DeleteSyntheticNodes()
for f, bar := range callgraph.Nodes {
fName := fmt.Sprintf("%+v", f)
_, ok := added[fName]
if !ok {
for _, edge := range bar.Out {
if extraImports[edge.Callee.Func.String()] == nil {
extraImports[edge.Callee.Func.String()] = make([]string, 0)
}
extraImports[edge.Callee.Func.String()] = append(extraImports[edge.Callee.Func.String()], strings.TrimPrefix(slug.Slug(fName), "package-"))
}
added[fName] = struct{}{}
}
}
added = make(map[string]struct{})
for f, bar := range callgraph.Nodes {
fName := fmt.Sprintf("%+v", f)
_, ok := added[fName]
if !ok {
var imports []string
for _, edge := range bar.In {
imports = append(imports, strings.TrimPrefix(slug.Slug(edge.Caller.Func.String()), "package-"))
}
imports = append(imports, extraImports[fName]...)
nodes = append(nodes, node.Node{Name: strings.TrimPrefix(slug.Slug(fName), "package-"), Imports: imports, Size: len(imports) * 100})
added[fName] = struct{}{}
}
}
return nodes, nil
}
示例12: Create
//Create adds a skill to the database, based on it's owner
func (r *SkillRepo) Create(skill *Skill) error {
id := bson.NewObjectId()
Slug := slug.Slug(skill.Name + " " + skill.City + " " + randSeq(7))
skill.Slug = Slug
_, err := r.coll.UpsertId(id, skill)
if err != nil {
return err
}
skill.ID = id
return nil
}
示例13: GetSlug
func GetSlug(content *Content) (string, error) {
s := slug.Slug(content.Title)
// Let's check if this slug already exists,
// if existis, we will increment a sulfix to it
newSlug := s
increment := 1
count, err := db.SelectInt("select count(*) from content where contentid!=? AND slug=?", content.ContentId, newSlug)
for err == nil && count != 0 {
increment += 1
newSlug = fmt.Sprintf("%s-%d", s, increment)
count, err = db.SelectInt("select count(*) from content where contentid!=? AND slug=?", content.ContentId, newSlug)
}
if err != nil {
return "", err
}
log.Printf("SLUG: %s, inc: %d, count: %d\n", newSlug, increment, count)
return newSlug, nil
}
示例14: xmain
func (c *appContext) xmain() {
inFile, err := os.Open("./places.json")
if err != nil {
log.Println(err)
}
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
//var pp []place
for scanner.Scan() {
//log.Println(scanner.Text())
type Placex struct {
ID bson.ObjectId `bson:"_id,omitempty"`
Slug string
Location string
State string
Budget string
Service []string
Name string
Overview string
Address string
WorkingHours string
Phone string
PriceRange string
Owner string
//Timestamp string
Images []Images
Rating int
}
var p Placex
err := json.Unmarshal([]byte(scanner.Text()), &p)
if err != nil {
log.Println(err)
}
//log.Println(p.Images)
//pp = append(pp, p)
var services []string
for _, s := range strings.Split(p.Service[0], " ") {
log.Println(s)
c.redis.SAdd("services", strings.Title(strings.ToLower(s)))
services = append(services, strings.ToLower(s))
}
c.redis.SAdd("places", strings.Title(strings.ToLower(p.Location)+", Lagos"))
xx := &place{
Location: strings.ToLower(p.Location),
State: "lagos",
Name: strings.ToLower(p.Name),
Budget: strings.ToLower(p.Budget),
Service: services,
Overview: p.Overview,
Address: p.Address,
WorkingHours: p.WorkingHours,
Phone: p.Phone,
Timestamp: time.Now(),
Images: p.Images,
Owner: p.Owner,
Slug: slug.Slug(p.Name + " " + p.Location + " " + randSeq(5)),
}
cc := c.db.C("places")
err = cc.Insert(xx)
if err != nil {
log.Println(err)
}
}
}
示例15: newPlace
func (c *appContext) newPlace(w http.ResponseWriter, r *http.Request, approve int) error {
user, err := userget(r)
if err != nil {
log.Println(err)
}
log.Println(user)
err = r.ParseMultipartForm(20000)
if err != nil {
log.Println(err)
return err
}
f := r.MultipartForm
files := f.File["images"] // grab filenames
log.Println(files)
var img = make([]Images, 0, 10)
for _, v := range files {
fn, tn := c.uploadPic(v)
i := Images{
Thumb: tn,
Full: fn,
}
img = append(img, i)
}
location := strings.ToLower(strings.Join(r.Form["location"], ""))
budget := strings.Join(r.Form["budget"], "")
service := strings.Split(strings.ToLower(strings.Join(r.Form["service"], "")), ",")
Place := &place{
Approved: approve,
Location: location,
Budget: budget,
Service: service,
State: strings.Join(r.Form["state"], ""),
Name: strings.Join(r.Form["name"], ""),
Address: strings.Join(r.Form["address"], ""),
Overview: strings.Join(r.Form["overview"], ""),
WorkingHours: strings.Join(r.Form["working-hours"], ""),
Phone: strings.Join(r.Form["phone"], ""),
PriceRange: strings.Join(r.Form["price-range"], ""),
Owner: user.ID,
Timestamp: time.Now(),
Images: img[:],
}
Place.Slug = slug.Slug(Place.Name + " " + Place.Location + " " + randSeq(5))
cc := c.db.C("places")
err = cc.Insert(Place)
if err != nil {
log.Println(err)
return err
}
for _, s := range service {
log.Println(s)
c.redis.SAdd("services", strings.Title(s))
}
c.redis.SAdd("places", strings.Title(Place.Location+", "+Place.State))
return nil
}