func parseTagBrief(
	tagBriefData []byte, tagsFetchOpts *storage.TagsFetchOpts,
) (bmTags []storage.BookmarkTagPath, err error) {
	if len(tagBriefData) == 0 {
		tagBriefData = []byte("{}")
	}

	var tagBriefMap tagBriefMap
	if err := json.Unmarshal(tagBriefData, &tagBriefMap); err != nil {
		return nil, hh.MakeInternalServerError(err)
	}

	thier := taghier.New(tagBriefMap)
	for _, t := range tagBriefMap {
		thier.Add(t.ID)
	}

	var bkmTagIDs []int
	switch tagsFetchOpts.TagsFetchMode {
	case storage.TagsFetchModeLeafs:
		bkmTagIDs = thier.GetLeafs()

	case storage.TagsFetchModeAll:
		bkmTagIDs = thier.GetAll()
	}

	for _, tagID := range bkmTagIDs {
		var tagPathItems []storage.BookmarkTagPathItem
		if tagsFetchOpts.TagNamesFetchMode == storage.TagNamesFetchModeFull {
			var err error
			tagPathItems, err = tagBriefMap.GetPath(tagID)
			if err != nil {
				return nil, errors.Trace(err)
			}
		}

		bmTags = append(bmTags, storage.BookmarkTagPath{
			TagItems: tagPathItems,
		})
	}

	return bmTags, nil
}
// parseTagBrief takes "tag brief data", and converts it to an array of
// storage.BookmarkTagPath.
//
// "tag brief data" is the following JSON data: a map from a tag id to JSON
// object which represents a PostgreSQL type gm_tag_brief: (id int, parent_id
// int, name text).
parseTagBrief takes "tag brief data", and converts it to an array of
storage.BookmarkTagPath.

"tag brief data" is the following JSON data: a map from a tag id to JSON
object which represents a PostgreSQL type gm_tag_brief: (id int, parent_id
int, name text).
// parseTagBrief takes " tag brief data " and converts it to an array of // storage . BookmarkTagPath . // // " tag brief data " is the following JSON data : a map from a tag id to JSON // object which represents a PostgreSQL type gm_tag_brief : ( id int parent_id // int name text ) .
func parseTagBrief(
	tagBriefData []byte, tagsFetchOpts *storage.TagsFetchOpts,
) (bmTags []storage.BookmarkTagPath, err error) {
	if len(tagBriefData) == 0 {
		tagBriefData = []byte("{}")
	}
	var tagBriefMap tagBriefMap
	if err := json.Unmarshal(tagBriefData, &tagBriefMap); err != nil {
		return nil, hh.MakeInternalServerError(err)
	}
	thier := taghier.New(tagBriefMap)
	for _, t := range tagBriefMap {
		thier.Add(t.ID)
	}
	var bkmTagIDs []int
	switch tagsFetchOpts.TagsFetchMode {
	case storage.TagsFetchModeLeafs:
		bkmTagIDs = thier.GetLeafs()
	case storage.TagsFetchModeAll:
		bkmTagIDs = thier.GetAll()
	}
	for _, tagID := range bkmTagIDs {
		var tagPathItems []storage.BookmarkTagPathItem
		if tagsFetchOpts.TagNamesFetchMode == storage.TagNamesFetchModeFull {
			var err error
			tagPathItems, err = tagBriefMap.GetPath(tagID)
			if err != nil {
				return nil, errors.Trace(err)
			}
		}
		bmTags = append(bmTags, storage.BookmarkTagPath{
			TagItems: tagPathItems,
		})
	}
	return bmTags, nil
}
func parseTagBrief ( tagBriefData [ ] byte , tagsFetchOpts * storage . TagsFetchOpts , ) ( bmTags [ ] storage . BookmarkTagPath , err error ) { if len ( tagBriefData ) == 0 { tagBriefData = [ ] byte ( " " ) } var tagBriefMap tagBriefMap if err := json . Unmarshal ( tagBriefData , & tagBriefMap ) ; err != nil { return nil , hh . MakeInternalServerError ( err ) } thier := taghier . New ( tagBriefMap ) for _ , t := range tagBriefMap { thier . Add ( t . ID ) } var bkmTagIDs [ ] int switch tagsFetchOpts . TagsFetchMode { case storage . TagsFetchModeLeafs : bkmTagIDs = thier . GetLeafs ( ) case storage . TagsFetchModeAll : bkmTagIDs = thier . GetAll ( ) } for _ , tagID := range bkmTagIDs { var tagPathItems [ ] storage . BookmarkTagPathItem if tagsFetchOpts . TagNamesFetchMode == storage . TagNamesFetchModeFull { var err error tagPathItems , err = tagBriefMap . GetPath ( tagID ) if err != nil { return nil , errors . Trace ( err ) } } bmTags = append ( bmTags , storage . BookmarkTagPath { TagItems : tagPathItems , } ) } return bmTags , nil }
parseTagBrief takes "tag brief data", and converts it to an array of
storage.BookmarkTagPath.
parseTagBrief takes " tag brief data " and converts it to an array of storage . BookmarkTagPath .