Exemplo n.º 1
0
Arquivo: file.go Projeto: e8vm/shanhu
func fileDat(db repodb.DB, c *context, route *repoRoute) (
	interface{}, error,
) {
	if route.file == "" {
		return nil, fmt.Errorf("%q is not a file", route.fullPath)
	}

	repo := route.Repo()
	f, err := db.LatestFile(repo, route.fullPath)
	if err != nil {
		return nil, err
	}

	var fc repodb.File
	if err := json.Unmarshal(f.Content, &fc); err != nil {
		return nil, err
	}

	type d struct {
		GoImport string
		UserInfo *userInfo
		Repo     string
		RepoUser string
		RepoName string
		Dirs     []string
		FileName string
		Commit   string

		Nline int
		File  template.HTML
	}

	return &d{
		GoImport: route.goImportMeta(),
		UserInfo: newUserInfo(c),
		Repo:     repo,
		RepoUser: route.owner,
		RepoName: route.repo,
		Dirs:     route.dirs,
		FileName: route.file,
		Commit:   shortCommit(f.Build),
		Nline:    fc.Nline,
		File:     template.HTML(string(fc.HTML)),
	}, nil
}