Ejemplo n.º 1
0
// SaveProject saves project information to database.
func SaveProject(pdoc *hv.Package, pfuncs []models.PkgFunc) (int64, error) {
	// Save package information.
	pinfo := pdoc.PkgInfo
	pinfo.ViewedTime = time.Now().UTC().Unix()
	pinfo.Created = time.Now().UTC().Unix()

	// Save package declaration and functions.
	pdecl := &models.PkgDecl{
		Tag:          pdoc.Tag,
		JsNum:        pdoc.JsNum,
		IsHasExport:  pdoc.IsHasExport,
		IsHasConst:   pdoc.IsHasConst,
		IsHasVar:     pdoc.IsHasVar,
		IsHasExample: pdoc.IsHasExample,
		IsHasFile:    pdoc.IsHasFile,
		IsHasSubdir:  pdoc.IsHasSubdir,
	}

	// Imports.
	pdecl.Imports = strings.Join(pdoc.Imports, "|")
	pdecl.TestImports = strings.Join(pdoc.TestImports, "|")

	// Only save the latest functions.
	if len(pdoc.Tag) > 0 {
		pfuncs = nil
	}

	err := models.SaveProject(pinfo, pdecl, pfuncs, pdoc.Imports)
	return pinfo.Id, err
}
Ejemplo n.º 2
0
// Get implemented Get method for RefreshController.
// It serves refresh page of Go Walker.
func (this *RefreshController) Get() {
	// Set language version.
	curLang, restLangs := setLangVer(this.Ctx.Request, this.Input())

	// Save language information in cookies.
	this.Ctx.SetCookie("lang", curLang.Lang+";path=/", 0)

	// Get query field
	q := this.Input().Get("q")

	// Empty query string shows home page
	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	// Set properties
	this.Layout = "layout_" + curLang.Lang + ".html"
	this.TplNames = "refresh_" + curLang.Lang + ".html"

	// Set language properties.
	this.Data["Lang"] = curLang.Lang
	this.Data["CurLang"] = curLang.Name
	this.Data["RestLangs"] = restLangs

	pdoc, err := doc.CheckDoc(q, doc.REFRESH_REQUEST)
	if err == nil {
		pinfo := &models.PkgInfo{
			Path:        pdoc.ImportPath,
			Synopsis:    pdoc.Synopsis,
			Created:     pdoc.Created,
			ProName:     pdoc.ProjectName,
			ViewedTime:  pdoc.ViewedTime,
			Views:       pdoc.Views,
			Etag:        pdoc.Etag,
			Tags:        pdoc.Tags,
			ImportedNum: pdoc.ImportedNum,
			ImportPid:   pdoc.ImportPid,
		}
		models.SaveProject(pinfo, nil, nil, nil)
		// Show search page
		this.Redirect("/"+q, 302)
		return
	}

	// Set data
	this.Data["Path"] = q
	this.Data["LimitTime"] = err.Error()
}
Ejemplo n.º 3
0
// Get implemented Get method for RefreshRouter.
func (this *RefreshRouter) Get() {
	// Set language version.
	curLang := globalSetting(this.Ctx, this.Input(), this.Data)

	// Get argument(s).
	q := this.Input().Get("q")

	// Empty query string shows home page.
	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	// Set properties.
	this.TplNames = "refresh_" + curLang.Lang + ".html"

	pdoc, err := doc.CheckDoc(q, "", doc.REFRESH_REQUEST)
	if err == nil {
		pinfo := &models.PkgInfo{
			Path:        pdoc.ImportPath,
			ProName:     pdoc.ProjectName,
			Synopsis:    pdoc.Synopsis,
			IsCmd:       pdoc.IsCmd,
			Tags:        strings.Join(pdoc.Tags, "|||"),
			Views:       pdoc.Views,
			ViewedTime:  pdoc.ViewedTime,
			Created:     pdoc.Created,
			Rank:        pdoc.Rank,
			Etag:        pdoc.Etag,
			Labels:      pdoc.Labels,
			ImportedNum: pdoc.ImportedNum,
			ImportPid:   pdoc.ImportPid,
			Note:        pdoc.Note,
		}
		models.SaveProject(pinfo, nil, nil, nil)

		this.Redirect("/"+q, 302)
		return
	}

	this.Data["Path"] = q
	this.Data["LimitTime"] = err.Error()
}
Ejemplo n.º 4
0
// SaveProject saves project information to database.
func SaveProject(pdoc *Package) error {

	// Save package information.
	pinfo := &models.PkgInfo{
		Path:       pdoc.ImportPath,
		Synopsis:   pdoc.Synopsis,
		Created:    time.Now().UTC(),
		ViewedTime: time.Now().UTC().Unix(),
		ProName:    pdoc.ProjectName,
		Etag:       pdoc.Etag,
	}

	// Save package declaration.
	pdecl := &models.PkgDecl{
		Path:      pdoc.ImportPath,
		Doc:       pdoc.Doc,
		Truncated: pdoc.Truncated,
		Goos:      pdoc.GOOS,
		Goarch:    pdoc.GOARCH,
	}
	var buf bytes.Buffer

	// Consts.
	addValues(&buf, &pdecl.Consts, pdoc.Consts)
	buf.Reset()
	addValues(&buf, &pdecl.Iconsts, pdoc.Iconsts)

	// Variables.
	buf.Reset()
	addValues(&buf, &pdecl.Vars, pdoc.Vars)
	buf.Reset()
	addValues(&buf, &pdecl.Ivars, pdoc.Ivars)

	// Functions.
	buf.Reset()
	addFuncs(&buf, &pdecl.Funcs, pdoc.Funcs)
	buf.Reset()
	addFuncs(&buf, &pdecl.Ifuncs, pdoc.Ifuncs)

	// Types.
	buf.Reset()
	for _, v := range pdoc.Types {
		buf.WriteString(v.Name)
		buf.WriteString("&T#")
		buf.WriteString(v.Doc)
		buf.WriteString("&T#")
		buf.WriteString(v.Decl)
		buf.WriteString("&T#")
		buf.WriteString(v.URL)
		buf.WriteString("&$#")
		// Functions.
		for _, m := range v.Funcs {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*codeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")
		for _, m := range v.IFuncs {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*codeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")

		// Methods.
		for _, m := range v.Methods {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*codeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")
		for _, m := range v.IMethods {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*codeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&##")
	}
	pdecl.Types = buf.String()

	// Notes.
	buf.Reset()
	for _, s := range pdoc.Notes {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Notes = buf.String()

	// Dirs.
	buf.Reset()
	for _, s := range pdoc.Dirs {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Dirs = buf.String()

	// Imports.
	buf.Reset()
	for _, s := range pdoc.Imports {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Imports = buf.String()

	buf.Reset()
	for _, s := range pdoc.TestImports {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.TestImports = buf.String()

	// Files.
	buf.Reset()
	for _, s := range pdoc.Files {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Files = buf.String()

	buf.Reset()
	for _, s := range pdoc.TestFiles {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.TestFiles = buf.String()

	// Save package documentation.
	doc := &models.PkgDoc{
		Path: pdoc.ImportPath,
		Lang: "zh",
	}

	// Documentataion.
	buf.Reset()
	for k, v := range pdoc.TDoc {
		buf.WriteString(k)
		buf.WriteByte(':')
		buf.WriteString(v)
		buf.WriteString("&$#")
	}

	for k, v := range pdoc.IDoc {
		buf.WriteString(k)
		buf.WriteByte(':')
		buf.WriteString(v)
		buf.WriteString("&$#")
	}
	doc.Doc = buf.String()

	err := models.SaveProject(pinfo, pdecl, doc)
	return err
}
Ejemplo n.º 5
0
// SaveProject saves project information to database.
func SaveProject(pdoc *Package, info *models.PkgInfo) error {

	// Save package information.
	pinfo := &models.PkgInfo{
		Path:        pdoc.ImportPath,
		Tags:        strings.Join(pdoc.Tags, "|||"),
		IsCmd:       pdoc.IsCmd,
		Synopsis:    pdoc.Synopsis,
		Views:       info.Views,
		Created:     time.Now().UTC(),
		ViewedTime:  time.Now().UTC().Unix(),
		ProName:     pdoc.ProjectName,
		Etag:        pdoc.Etag,
		Labels:      pdoc.Labels,
		ImportedNum: info.ImportedNum,
		ImportPid:   info.ImportPid,
	}

	// Save package declaration.
	pdecl := &models.PkgDecl{
		Path: pdoc.ImportPath,
		Tag:  pdoc.Tag,
		Doc:  pdoc.Doc,
	}
	var buf bytes.Buffer

	// Consts.
	addValues(&buf, &pdecl.Consts, pdoc.Consts)
	buf.Reset()
	addValues(&buf, &pdecl.Iconsts, pdoc.Iconsts)

	// Variables.
	buf.Reset()
	addValues(&buf, &pdecl.Vars, pdoc.Vars)
	buf.Reset()
	addValues(&buf, &pdecl.Ivars, pdoc.Ivars)

	// Functions.
	buf.Reset()
	addFuncs(&buf, &pdecl.Funcs, pdoc.Funcs)
	buf.Reset()
	addFuncs(&buf, &pdecl.Ifuncs, pdoc.Ifuncs)

	// Types.
	buf.Reset()
	for _, v := range pdoc.Types {
		buf.WriteString(v.Name)
		buf.WriteString("&T#")
		buf.WriteString(v.Doc)
		buf.WriteString("&T#")
		buf.WriteString(v.Decl)
		buf.WriteString("&T#")
		buf.WriteString(v.URL)
		buf.WriteString("&$#")
		// Functions.
		for _, m := range v.Funcs {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*CodeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")
		for _, m := range v.IFuncs {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*CodeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")

		// Methods.
		for _, m := range v.Methods {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*CodeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")
		for _, m := range v.IMethods {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			buf.WriteString(*CodeEncode(&m.Code))
			buf.WriteString("&M#")
		}
		buf.WriteString("&##")
	}
	pdecl.Types = buf.String()

	// Examples.
	buf.Reset()
	for _, e := range pdoc.Examples {
		buf.WriteString(e.Name)
		buf.WriteString("&E#")
		buf.WriteString(e.Doc)
		buf.WriteString("&E#")
		buf.WriteString(*CodeEncode(&e.Code))
		buf.WriteString("&E#")
		// buf.WriteString(e.Play)
		// buf.WriteString("&E#")
		buf.WriteString(e.Output)
		buf.WriteString("&$#")
	}
	pdecl.Examples = buf.String()

	// Notes.
	buf.Reset()
	for _, s := range pdoc.Notes {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Notes = buf.String()

	// Dirs.
	buf.Reset()
	for _, s := range pdoc.Dirs {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Dirs = buf.String()

	// Imports.
	buf.Reset()
	for _, s := range pdoc.Imports {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Imports = buf.String()

	buf.Reset()
	for _, s := range pdoc.TestImports {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.TestImports = buf.String()

	// Files.
	buf.Reset()
	for _, s := range pdoc.Files {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.Files = buf.String()

	buf.Reset()
	for _, s := range pdoc.TestFiles {
		buf.WriteString(s)
		buf.WriteString("|")
	}
	pdecl.TestFiles = buf.String()

	// Save package documentation.
	doc := &models.PkgDoc{
		Path: pdoc.ImportPath,
		Lang: "zh",
	}

	// Documentataion.
	buf.Reset()
	doc.Doc = buf.String()

	err := models.SaveProject(pinfo, pdecl, doc, pdoc.Imports)
	return err
}
Ejemplo n.º 6
0
// SaveProject saves project information to database.
func SaveProject(pdoc *Package, info *models.PkgInfo) (int64, error) {
	// Save package information.
	pinfo := &models.PkgInfo{
		Path:        pdoc.ImportPath,
		ProName:     pdoc.ProjectName,
		Synopsis:    pdoc.Synopsis,
		IsCmd:       pdoc.IsCmd,
		Tags:        strings.Join(pdoc.Tags, "|||"),
		Views:       info.Views,
		ViewedTime:  time.Now().UTC().Unix(),
		Created:     time.Now().UTC(),
		Rank:        pdoc.Rank,
		Etag:        pdoc.Etag,
		Labels:      pdoc.Labels,
		ImportedNum: info.ImportedNum,
		ImportPid:   info.ImportPid,
		Note:        pdoc.Note,
	}

	// Save package declaration and functions.
	pdecl := &models.PkgDecl{
		Tag: pdoc.Tag,
		Doc: pdoc.Doc,
	}
	pfuncs := make([]*models.PkgFunc, 0, len(pdoc.Funcs)+len(pdoc.Types)*3)
	var buf bytes.Buffer

	// Consts.
	addValues(&buf, &pdecl.Consts, pdoc.Consts)
	addValues(&buf, &pdecl.Iconsts, pdoc.Iconsts)

	// Variables.
	addValues(&buf, &pdecl.Vars, pdoc.Vars)
	addValues(&buf, &pdecl.Ivars, pdoc.Ivars)

	links := getLinks(pdoc)

	// Functions.
	pfuncs = addFuncs(pfuncs, pdoc.Funcs, pinfo.Path, &buf, &pdecl.Funcs, links)
	pfuncs = addFuncs(pfuncs, pdoc.Ifuncs, pinfo.Path, &buf, &pdecl.Ifuncs, links)

	// Types.
	buf.Reset()
	for _, v := range pdoc.Types {
		buf.WriteString(v.Name)
		buf.WriteString("&T#")
		buf.WriteString(v.Doc)
		buf.WriteString("&T#")
		buf.WriteString(v.Decl)
		buf.WriteString("&T#")
		buf.WriteString(v.URL)
		buf.WriteString("&$#")
		// Constats.
		for _, c := range v.Consts {
			buf.WriteString(c.Name)
			buf.WriteString("&V#")
			buf.WriteString(c.Doc)
			buf.WriteString("&V#")
			buf.WriteString(c.Decl)
			buf.WriteString("&V#")
			buf.WriteString(c.URL)
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")
		// Variables.
		for _, c := range v.Vars {
			buf.WriteString(c.Name)
			buf.WriteString("&V#")
			buf.WriteString(c.Doc)
			buf.WriteString("&V#")
			buf.WriteString(c.Decl)
			buf.WriteString("&V#")
			buf.WriteString(c.URL)
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")

		// Functions.
		for _, m := range v.Funcs {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			pfuncs = addFunc(pfuncs, m, pinfo.Path, m.Name, links)
			buf.WriteString(m.Code)
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")
		for _, m := range v.IFuncs {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			pfuncs = addFunc(pfuncs, m, pinfo.Path, m.Name, links)
			buf.WriteString(m.Code)
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")

		// Methods.
		for _, m := range v.Methods {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			pfuncs = addFunc(pfuncs, m, pinfo.Path, v.Name+"_"+m.Name, links)
			buf.WriteString(m.Code)
			buf.WriteString("&M#")
		}
		buf.WriteString("&$#")
		for _, m := range v.IMethods {
			buf.WriteString(m.Name)
			buf.WriteString("&F#")
			buf.WriteString(m.Doc)
			buf.WriteString("&F#")
			buf.WriteString(m.Decl)
			buf.WriteString("&F#")
			buf.WriteString(m.URL)
			buf.WriteString("&F#")
			pfuncs = addFunc(pfuncs, m, pinfo.Path, v.Name+"_"+m.Name, links)
			buf.WriteString(m.Code)
			buf.WriteString("&M#")
		}
		buf.WriteString("&##")
	}
	pdecl.Types = buf.String()

	// Examples.
	buf.Reset()
	for _, e := range pdoc.Examples {
		buf.WriteString(e.Name)
		buf.WriteString("&E#")
		buf.WriteString(e.Doc)
		buf.WriteString("&E#")
		buf.WriteString(*CodeEncode(&e.Code))
		buf.WriteString("&E#")
		// buf.WriteString(e.Play)
		// buf.WriteString("&E#")
		buf.WriteString(e.Output)
		buf.WriteString("&$#")
	}
	pdecl.Examples = buf.String()

	// Notes.
	pdecl.Notes = strings.Join(pdoc.Notes, "|")

	// Dirs.
	pdecl.Dirs = strings.Join(pdoc.Dirs, "|")

	// Imports.
	pdecl.Imports = strings.Join(pdoc.Imports, "|")
	pdecl.TestImports = strings.Join(pdoc.TestImports, "|")

	// Files.
	pdecl.Files = strings.Join(pdoc.Files, "|")
	pdecl.TestFiles = strings.Join(pdoc.TestFiles, "|")

	err := models.SaveProject(pinfo, pdecl, pfuncs, pdoc.Imports)
	return pinfo.Id, err
}