Пример #1
0
func updateCacheInfo(pdoc *doc.Package, urpids, urpts *http.Cookie) (string, string) {
	pdoc.ViewedTime = time.Now().UTC().Unix()

	updateCachePros(pdoc)
	updateProInfos(pdoc)
	return updateUrPros(pdoc, urpids, urpts)
}
Пример #2
0
func updateRecentPros(pdoc *doc.Package) {
	// Only projects with import path length is less than 40 letters will be showed.
	if len(pdoc.ImportPath) < 40 {
		index := -1
		listLen := len(recentViewedPros)
		curPro := &recentPro{
			Path:       pdoc.ImportPath,
			Synopsis:   pdoc.Synopsis,
			ViewedTime: time.Now().UTC().Unix(),
			IsGoRepo: pdoc.ProjectName == "Go" &&
				strings.Index(pdoc.ImportPath, ".") == -1,
			Views: pdoc.Views,
		}

		pdoc.ViewedTime = curPro.ViewedTime

		// Check if in the list
		for i, s := range recentViewedPros {
			if s.Path == curPro.Path {
				index = i
				break
			}
		}

		s := make([]*recentPro, 0, recentViewedProNum)
		s = append(s, curPro)
		switch {
		case index == -1 && listLen < recentViewedProNum:
			// Not found and list is not full
			s = append(s, recentViewedPros...)
		case index == -1 && listLen >= recentViewedProNum:
			// Not found but list is full
			s = append(s, recentViewedPros[:recentViewedProNum-1]...)
		case index > -1:
			// Found
			s = append(s, recentViewedPros[:index]...)
			s = append(s, recentViewedPros[index+1:]...)
		}
		recentViewedPros = s
	}
}
Пример #3
0
func updateRecentPros(pdoc *doc.Package) {
	index := -1
	listLen := len(recentViewedPros)
	curPro := &recentPro{
		Path:       pdoc.ImportPath,
		ViewedTime: time.Now().UTC().Unix(),
		IsGoRepo:   pdoc.ProjectName == "Go",
		Views:      pdoc.Views,
	}

	pdoc.ViewedTime = curPro.ViewedTime

	// Check if in the list
	for i, s := range recentViewedPros {
		if s.Path == curPro.Path {
			index = i
			break
		}
	}

	s := make([]*recentPro, 0, recentViewedProNum)
	s = append(s, curPro)
	switch {
	case index == -1 && listLen < recentViewedProNum:
		// Not found and list is not full
		s = append(s, recentViewedPros...)
	case index == -1 && listLen >= recentViewedProNum:
		// Not found but list is full
		s = append(s, recentViewedPros[:recentViewedProNum-1]...)
	case index > -1:
		// Found
		s = append(s, recentViewedPros[:index]...)
		s = append(s, recentViewedPros[index+1:]...)
	}
	recentViewedPros = s
}
Пример #4
0
// ConvertDataFormat converts data from database acceptable format to useable format.
func ConvertDataFormat(pdoc *doc.Package, pdecl *models.PkgDecl) error {
	// Consts
	pdoc.Consts = make([]*doc.Value, 0, 5)
	for _, v := range strings.Split(pdecl.Consts, "&$#") {
		val := new(doc.Value)
		for j, s := range strings.Split(v, "&V#") {
			switch j {
			case 0: // Name
				val.Name = s
			case 1: // Doc
				val.Doc = s
			case 2: // Decl
				val.Decl = s
			case 3: // URL
				val.URL = s
			}
		}
		pdoc.Consts = append(pdoc.Consts, val)
	}
	pdoc.Consts = pdoc.Consts[:len(pdoc.Consts)-1]

	// Variables
	pdoc.Vars = make([]*doc.Value, 0, 5)
	for _, v := range strings.Split(pdecl.Vars, "&$#") {
		val := new(doc.Value)
		for j, s := range strings.Split(v, "&V#") {
			switch j {
			case 0: // Name
				val.Name = s
			case 1: // Doc
				val.Doc = s
			case 2: // Decl
				val.Decl = s
			case 3: // URL
				val.URL = s
			}
		}
		pdoc.Vars = append(pdoc.Vars, val)
	}
	pdoc.Vars = pdoc.Vars[:len(pdoc.Vars)-1]

	// Functions
	pdoc.Funcs = make([]*doc.Func, 0, 10)
	for _, v := range strings.Split(pdecl.Funcs, "&$#") {
		val := new(doc.Func)
		for j, s := range strings.Split(v, "&F#") {
			switch j {
			case 0: // Name
				val.Name = s
			case 1: // Doc
				val.Doc = s
			case 2: // Decl
				val.Decl = s
			case 3: // URL
				val.URL = s
			case 4: // Code
				val.Code = *codeDecode(&s)
			}
		}
		pdoc.Funcs = append(pdoc.Funcs, val)
	}
	pdoc.Funcs = pdoc.Funcs[:len(pdoc.Funcs)-1]

	// Types
	pdoc.Types = make([]*doc.Type, 0, 10)
	for _, v := range strings.Split(pdecl.Types, "&##") {
		val := new(doc.Type)
		for j, s := range strings.Split(v, "&$#") {
			switch j {
			case 0: // Type
				for y, s2 := range strings.Split(s, "&T#") {
					switch y {
					case 0: // Name
						val.Name = s2
					case 1: // Doc
						val.Doc = s2
					case 2: // Decl
						val.Decl = s2
					case 3: // URL
						val.URL = s2
					}
				}
			case 1: // Functions
				val.Funcs = make([]*doc.Func, 0, 2)
				for _, v2 := range strings.Split(s, "&M#") {
					val2 := new(doc.Func)
					for y, s2 := range strings.Split(v2, "&F#") {
						switch y {
						case 0: // Name
							val2.Name = s2
						case 1: // Doc
							val2.Doc = s2
						case 2: // Decl
							val2.Decl = s2
						case 3: // URL
							val2.URL = s2
						case 4: // Code
							val2.Code = *codeDecode(&s2)
						}
					}
					val.Funcs = append(val.Funcs, val2)
				}
				val.Funcs = val.Funcs[:len(val.Funcs)-1]
			case 3: // Methods.
				val.Methods = make([]*doc.Func, 0, 5)
				for _, v2 := range strings.Split(s, "&M#") {
					val2 := new(doc.Func)
					for y, s2 := range strings.Split(v2, "&F#") {
						switch y {
						case 0: // Name
							val2.Name = s2
						case 1: // Doc
							val2.Doc = s2
						case 2: // Decl
							val2.Decl = s2
						case 3: // URL
							val2.URL = s2
						case 4: // Code
							val2.Code = *codeDecode(&s2)
						}
					}
					val.Methods = append(val.Methods, val2)
				}
				val.Methods = val.Methods[:len(val.Methods)-1]
			}
		}
		pdoc.Types = append(pdoc.Types, val)
	}
	pdoc.Types = pdoc.Types[:len(pdoc.Types)-1]

	// Dirs.
	pdoc.Dirs = strings.Split(pdecl.Dirs, "|")
	pdoc.Dirs = pdoc.Dirs[:len(pdoc.Dirs)-1]

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

	// Files.
	pdoc.Files = strings.Split(pdecl.Files, "|")
	return nil
}