Преглед изворни кода

refactor(googlereader): unexport a lot of symbols

Julien Voisin пре 8 месеци
родитељ
комит
0d5f4a710f

+ 31 - 31
internal/googlereader/handler.go

@@ -71,12 +71,12 @@ func checkAndSimplifyTags(addTags []Stream, removeTags []Stream) (map[StreamType
 		switch s.Type {
 		case ReadStream:
 			if _, ok := tags[KeptUnreadStream]; ok {
-				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", KeptUnread, Read)
+				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", keptUnread, read)
 			}
 			tags[ReadStream] = true
 		case KeptUnreadStream:
 			if _, ok := tags[ReadStream]; ok {
-				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", KeptUnread, Read)
+				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", keptUnread, read)
 			}
 			tags[ReadStream] = false
 		case StarredStream:
@@ -91,17 +91,17 @@ func checkAndSimplifyTags(addTags []Stream, removeTags []Stream) (map[StreamType
 		switch s.Type {
 		case ReadStream:
 			if _, ok := tags[ReadStream]; ok {
-				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", KeptUnread, Read)
+				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", keptUnread, read)
 			}
 			tags[ReadStream] = false
 		case KeptUnreadStream:
 			if _, ok := tags[ReadStream]; ok {
-				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", KeptUnread, Read)
+				return nil, fmt.Errorf("googlereader: %s and %s should not be supplied simultaneously", keptUnread, read)
 			}
 			tags[ReadStream] = true
 		case StarredStream:
 			if _, ok := tags[StarredStream]; ok {
-				return nil, fmt.Errorf("googlereader: %s should not be supplied for add and remove simultaneously", Starred)
+				return nil, fmt.Errorf("googlereader: %s should not be supplied for add and remove simultaneously", starred)
 			}
 			tags[StarredStream] = false
 		case BroadcastStream, LikeStream:
@@ -269,12 +269,12 @@ func (h *handler) editTagHandler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	addTags, err := getStreams(r.PostForm[ParamTagsAdd], userID)
+	addTags, err := getStreams(r.PostForm[paramTagsAdd], userID)
 	if err != nil {
 		json.ServerError(w, r, err)
 		return
 	}
-	removeTags, err := getStreams(r.PostForm[ParamTagsRemove], userID)
+	removeTags, err := getStreams(r.PostForm[paramTagsRemove], userID)
 	if err != nil {
 		json.ServerError(w, r, err)
 		return
@@ -407,7 +407,7 @@ func (h *handler) quickAddHandler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	feedURL := r.Form.Get(ParamQuickAdd)
+	feedURL := r.Form.Get(paramQuickAdd)
 	if !validator.IsValidURL(feedURL) {
 		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid URL: %s", feedURL))
 		return
@@ -456,7 +456,7 @@ func (h *handler) quickAddHandler(w http.ResponseWriter, r *http.Request) {
 	json.OK(w, r, quickAddResponse{
 		NumResults: 1,
 		Query:      newFeed.FeedURL,
-		StreamID:   fmt.Sprintf(FeedPrefix+"%d", newFeed.ID),
+		StreamID:   fmt.Sprintf(feedPrefix+"%d", newFeed.ID),
 		StreamName: newFeed.Title,
 	})
 }
@@ -609,20 +609,20 @@ func (h *handler) editSubscriptionHandler(w http.ResponseWriter, r *http.Request
 		return
 	}
 
-	streamIds, err := getStreams(r.Form[ParamStreamID], userID)
+	streamIds, err := getStreams(r.Form[paramStreamID], userID)
 	if err != nil || len(streamIds) == 0 {
 		json.BadRequest(w, r, errors.New("googlereader: no valid stream IDs provided"))
 		return
 	}
 
-	newLabel, err := getStream(r.Form.Get(ParamTagsAdd), userID)
+	newLabel, err := getStream(r.Form.Get(paramTagsAdd), userID)
 	if err != nil {
-		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", ParamTagsAdd))
+		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", paramTagsAdd))
 		return
 	}
 
-	title := r.Form.Get(ParamTitle)
-	action := r.Form.Get(ParamSubscribeAction)
+	title := r.Form.Get(paramTitle)
+	action := r.Form.Get(paramSubscribeAction)
 
 	switch action {
 	case "subscribe":
@@ -649,7 +649,7 @@ func (h *handler) editSubscriptionHandler(w http.ResponseWriter, r *http.Request
 			}
 		}
 
-		if r.Form.Has(ParamTagsAdd) {
+		if r.Form.Has(paramTagsAdd) {
 			if newLabel.Type != LabelStream {
 				json.BadRequest(w, r, errors.New("destination must be a label"))
 				return
@@ -701,9 +701,9 @@ func (h *handler) streamItemContentsHandler(w http.ResponseWriter, r *http.Reque
 		return
 	}
 
-	userReadingList := fmt.Sprintf(UserStreamPrefix, userID) + ReadingList
-	userRead := fmt.Sprintf(UserStreamPrefix, userID) + Read
-	userStarred := fmt.Sprintf(UserStreamPrefix, userID) + Starred
+	userReadingList := fmt.Sprintf(userStreamPrefix, userID) + readingList
+	userRead := fmt.Sprintf(userStreamPrefix, userID) + read
+	userStarred := fmt.Sprintf(userStreamPrefix, userID) + starred
 
 	itemIDs, err := parseItemIDsFromRequest(r)
 	if err != nil {
@@ -752,7 +752,7 @@ func (h *handler) streamItemContentsHandler(w http.ResponseWriter, r *http.Reque
 		categories := make([]string, 0)
 		categories = append(categories, userReadingList)
 		if entry.Feed.Category.Title != "" {
-			categories = append(categories, fmt.Sprintf(UserLabelPrefix, userID)+entry.Feed.Category.Title)
+			categories = append(categories, fmt.Sprintf(userLabelPrefix, userID)+entry.Feed.Category.Title)
 		}
 		if entry.Status == model.EntryStatusRead {
 			categories = append(categories, userRead)
@@ -822,9 +822,9 @@ func (h *handler) disableTagHandler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	streams, err := getStreams(r.Form[ParamStreamID], userID)
+	streams, err := getStreams(r.Form[paramStreamID], userID)
 	if err != nil {
-		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", ParamStreamID))
+		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", paramStreamID))
 		return
 	}
 
@@ -862,15 +862,15 @@ func (h *handler) renameTagHandler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	source, err := getStream(r.Form.Get(ParamStreamID), userID)
+	source, err := getStream(r.Form.Get(paramStreamID), userID)
 	if err != nil {
-		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", ParamStreamID))
+		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", paramStreamID))
 		return
 	}
 
-	destination, err := getStream(r.Form.Get(ParamDestination), userID)
+	destination, err := getStream(r.Form.Get(paramDestination), userID)
 	if err != nil {
-		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", ParamDestination))
+		json.BadRequest(w, r, fmt.Errorf("googlereader: invalid data in %s", paramDestination))
 		return
 	}
 
@@ -936,11 +936,11 @@ func (h *handler) tagListHandler(w http.ResponseWriter, r *http.Request) {
 	}
 	result.Tags = make([]subscriptionCategory, 0)
 	result.Tags = append(result.Tags, subscriptionCategory{
-		ID: fmt.Sprintf(UserStreamPrefix, userID) + Starred,
+		ID: fmt.Sprintf(userStreamPrefix, userID) + starred,
 	})
 	for _, category := range categories {
 		result.Tags = append(result.Tags, subscriptionCategory{
-			ID:    fmt.Sprintf(UserLabelPrefix, userID) + category.Title,
+			ID:    fmt.Sprintf(userLabelPrefix, userID) + category.Title,
 			Label: category.Title,
 			Type:  "folder",
 		})
@@ -973,10 +973,10 @@ func (h *handler) subscriptionListHandler(w http.ResponseWriter, r *http.Request
 	result.Subscriptions = make([]subscription, 0)
 	for _, feed := range feeds {
 		result.Subscriptions = append(result.Subscriptions, subscription{
-			ID:         fmt.Sprintf(FeedPrefix+"%d", feed.ID),
+			ID:         fmt.Sprintf(feedPrefix+"%d", feed.ID),
 			Title:      feed.Title,
 			URL:        feed.FeedURL,
-			Categories: []subscriptionCategory{{fmt.Sprintf(UserLabelPrefix, userID) + feed.Category.Title, feed.Category.Title, "folder"}},
+			Categories: []subscriptionCategory{{fmt.Sprintf(userLabelPrefix, userID) + feed.Category.Title, feed.Category.Title, "folder"}},
 			HTMLURL:    feed.SiteURL,
 			IconURL:    h.feedIconURL(feed),
 		})
@@ -1278,14 +1278,14 @@ func (h *handler) markAllAsReadHandler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	stream, err := getStream(r.Form.Get(ParamStreamID), userID)
+	stream, err := getStream(r.Form.Get(paramStreamID), userID)
 	if err != nil {
 		json.BadRequest(w, r, err)
 		return
 	}
 
 	var before time.Time
-	if timestampParamValue := r.Form.Get(ParamTimestamp); timestampParamValue != "" {
+	if timestampParamValue := r.Form.Get(paramTimestamp); timestampParamValue != "" {
 		timestampParsedValue, err := strconv.ParseInt(timestampParamValue, 10, 64)
 		if err != nil {
 			json.BadRequest(w, r, err)

+ 1 - 1
internal/googlereader/item.go

@@ -56,7 +56,7 @@ func parseItemID(itemIDValue string) (int64, error) {
 }
 
 func parseItemIDsFromRequest(r *http.Request) ([]int64, error) {
-	items := r.Form[ParamItemIDs]
+	items := r.Form[paramItemIDs]
 	if len(items) == 0 {
 		return nil, fmt.Errorf("googlereader: no items requested")
 	}

+ 32 - 32
internal/googlereader/parameters.go

@@ -4,36 +4,36 @@
 package googlereader // import "miniflux.app/v2/internal/googlereader"
 
 const (
-	// ParamItemIDs - name of the parameter with the item ids
-	ParamItemIDs = "i"
-	// ParamStreamID - name of the parameter containing the stream to be included
-	ParamStreamID = "s"
-	// ParamStreamExcludes - name of the parameter containing streams to be excluded
-	ParamStreamExcludes = "xt"
-	// ParamStreamFilters - name of the parameter containing streams to be included
-	ParamStreamFilters = "it"
-	// ParamStreamMaxItems - name of the parameter containing number of items per page/max items returned
-	ParamStreamMaxItems = "n"
-	// ParamStreamOrder - name of the parameter containing the sort criteria
-	ParamStreamOrder = "r"
-	// ParamStreamStartTime - name of the parameter containing epoch timestamp, filtering items older than
-	ParamStreamStartTime = "ot"
-	// ParamStreamStopTime - name of the parameter containing epoch timestamp, filtering items newer than
-	ParamStreamStopTime = "nt"
-	// ParamTagsRemove - name of the parameter containing tags (streams) to be removed
-	ParamTagsRemove = "r"
-	// ParamTagsAdd - name of the parameter containing tags (streams) to be added
-	ParamTagsAdd = "a"
-	// ParamSubscribeAction - name of the parameter indicating the action to take for subscription/edit
-	ParamSubscribeAction = "ac"
-	// ParamTitle - name of the parameter for the title of the subscription
-	ParamTitle = "t"
-	// ParamQuickAdd - name of the parameter for a URL being quick subscribed to
-	ParamQuickAdd = "quickadd"
-	// ParamDestination - name of the parameter for the new name of a tag
-	ParamDestination = "dest"
-	// ParamContinuation -  name of the parameter for callers to pass to receive the next page of results
-	ParamContinuation = "c"
-	// ParamStreamType - name of the parameter for unix timestamp
-	ParamTimestamp = "ts"
+	// paramItemIDs - name of the parameter with the item ids
+	paramItemIDs = "i"
+	// paramStreamID - name of the parameter containing the stream to be included
+	paramStreamID = "s"
+	// paramStreamExcludes - name of the parameter containing streams to be excluded
+	paramStreamExcludes = "xt"
+	// paramStreamFilters - name of the parameter containing streams to be included
+	paramStreamFilters = "it"
+	// paramStreamMaxItems - name of the parameter containing number of items per page/max items returned
+	paramStreamMaxItems = "n"
+	// paramStreamOrder - name of the parameter containing the sort criteria
+	paramStreamOrder = "r"
+	// paramStreamStartTime - name of the parameter containing epoch timestamp, filtering items older than
+	paramStreamStartTime = "ot"
+	// paramStreamStopTime - name of the parameter containing epoch timestamp, filtering items newer than
+	paramStreamStopTime = "nt"
+	// paramTagsRemove - name of the parameter containing tags (streams) to be removed
+	paramTagsRemove = "r"
+	// paramTagsAdd - name of the parameter containing tags (streams) to be added
+	paramTagsAdd = "a"
+	// paramSubscribeAction - name of the parameter indicating the action to take for subscription/edit
+	paramSubscribeAction = "ac"
+	// paramTitle - name of the parameter for the title of the subscription
+	paramTitle = "t"
+	// paramQuickAdd - name of the parameter for a URL being quick subscribed to
+	paramQuickAdd = "quickadd"
+	// paramDestination - name of the parameter for the new name of a tag
+	paramDestination = "dest"
+	// paramContinuation -  name of the parameter for callers to pass to receive the next page of results
+	paramContinuation = "c"
+	// paramTimestamp - name of the parameter for unix timestamp
+	paramTimestamp = "ts"
 )

+ 24 - 24
internal/googlereader/prefix_suffix.go

@@ -4,28 +4,28 @@
 package googlereader // import "miniflux.app/v2/internal/googlereader"
 
 const (
-	// StreamPrefix is the prefix for astreams (read/starred/reading list and so on)
-	StreamPrefix = "user/-/state/com.google/"
-	// UserStreamPrefix is the user specific prefix for streams (read/starred/reading list and so on)
-	UserStreamPrefix = "user/%d/state/com.google/"
-	// LabelPrefix is the prefix for a label stream
-	LabelPrefix = "user/-/label/"
-	// UserLabelPrefix is the user specific prefix prefix for a label stream
-	UserLabelPrefix = "user/%d/label/"
-	// FeedPrefix is the prefix for a feed stream
-	FeedPrefix = "feed/"
-	// Read is the suffix for read stream
-	Read = "read"
-	// Starred is the suffix for starred stream
-	Starred = "starred"
-	// ReadingList is the suffix for reading list stream
-	ReadingList = "reading-list"
-	// KeptUnread is the suffix for kept unread stream
-	KeptUnread = "kept-unread"
-	// Broadcast is the suffix for broadcast stream
-	Broadcast = "broadcast"
-	// BroadcastFriends is the suffix for broadcast friends stream
-	BroadcastFriends = "broadcast-friends"
-	// Like is the suffix for like stream
-	Like = "like"
+	// streamPrefix is the prefix for streams (read/starred/reading list and so on)
+	streamPrefix = "user/-/state/com.google/"
+	// userStreamPrefix is the user specific prefix for streams (read/starred/reading list and so on)
+	userStreamPrefix = "user/%d/state/com.google/"
+	// labelPrefix is the prefix for a label stream
+	labelPrefix = "user/-/label/"
+	// userLabelPrefix is the user specific prefix prefix for a label stream
+	userLabelPrefix = "user/%d/label/"
+	// feedPrefix is the prefix for a feed stream
+	feedPrefix = "feed/"
+	// read is the suffix for read stream
+	read = "read"
+	// starred is the suffix for starred stream
+	starred = "starred"
+	// readingList is the suffix for reading list stream
+	readingList = "reading-list"
+	// keptUnread is the suffix for kept unread stream
+	keptUnread = "kept-unread"
+	// broadcast is the suffix for broadcast stream
+	broadcast = "broadcast"
+	// broadcastFriends is the suffix for broadcast friends stream
+	broadcastFriends = "broadcast-friends"
+	// like is the suffix for like stream
+	like = "like"
 )

+ 8 - 8
internal/googlereader/request_modifier.go

@@ -64,28 +64,28 @@ func parseStreamFilterFromRequest(r *http.Request) (RequestModifiers, error) {
 		UserID:        userID,
 	}
 
-	streamOrder := request.QueryStringParam(r, ParamStreamOrder, "d")
+	streamOrder := request.QueryStringParam(r, paramStreamOrder, "d")
 	if streamOrder == "o" {
 		result.SortDirection = "asc"
 	}
 	var err error
-	result.Streams, err = getStreams(request.QueryStringParamList(r, ParamStreamID), userID)
+	result.Streams, err = getStreams(request.QueryStringParamList(r, paramStreamID), userID)
 	if err != nil {
 		return RequestModifiers{}, err
 	}
-	result.ExcludeTargets, err = getStreams(request.QueryStringParamList(r, ParamStreamExcludes), userID)
+	result.ExcludeTargets, err = getStreams(request.QueryStringParamList(r, paramStreamExcludes), userID)
 	if err != nil {
 		return RequestModifiers{}, err
 	}
 
-	result.FilterTargets, err = getStreams(request.QueryStringParamList(r, ParamStreamFilters), userID)
+	result.FilterTargets, err = getStreams(request.QueryStringParamList(r, paramStreamFilters), userID)
 	if err != nil {
 		return RequestModifiers{}, err
 	}
 
-	result.Count = request.QueryIntParam(r, ParamStreamMaxItems, 0)
-	result.Offset = request.QueryIntParam(r, ParamContinuation, 0)
-	result.StartTime = request.QueryInt64Param(r, ParamStreamStartTime, int64(0))
-	result.StopTime = request.QueryInt64Param(r, ParamStreamStopTime, int64(0))
+	result.Count = request.QueryIntParam(r, paramStreamMaxItems, 0)
+	result.Offset = request.QueryIntParam(r, paramContinuation, 0)
+	result.StartTime = request.QueryInt64Param(r, paramStreamStartTime, int64(0))
+	result.StopTime = request.QueryInt64Param(r, paramStreamStopTime, int64(0))
 	return result, nil
 }

+ 18 - 16
internal/googlereader/stream.go

@@ -72,32 +72,34 @@ func (st StreamType) String() string {
 
 func getStream(streamID string, userID int64) (Stream, error) {
 	switch {
-	case strings.HasPrefix(streamID, FeedPrefix):
-		return Stream{Type: FeedStream, ID: strings.TrimPrefix(streamID, FeedPrefix)}, nil
-	case strings.HasPrefix(streamID, fmt.Sprintf(UserStreamPrefix, userID)) || strings.HasPrefix(streamID, StreamPrefix):
-		id := strings.TrimPrefix(streamID, fmt.Sprintf(UserStreamPrefix, userID))
-		id = strings.TrimPrefix(id, StreamPrefix)
+	case strings.HasPrefix(streamID, feedPrefix):
+		return Stream{Type: FeedStream, ID: strings.TrimPrefix(streamID, feedPrefix)}, nil
+	case strings.HasPrefix(streamID, fmt.Sprintf(userStreamPrefix, userID)),
+		strings.HasPrefix(streamID, streamPrefix):
+		id := strings.TrimPrefix(streamID, fmt.Sprintf(userStreamPrefix, userID))
+		id = strings.TrimPrefix(id, streamPrefix)
 		switch id {
-		case Read:
+		case read:
 			return Stream{ReadStream, ""}, nil
-		case Starred:
+		case starred:
 			return Stream{StarredStream, ""}, nil
-		case ReadingList:
+		case readingList:
 			return Stream{ReadingListStream, ""}, nil
-		case KeptUnread:
+		case keptUnread:
 			return Stream{KeptUnreadStream, ""}, nil
-		case Broadcast:
+		case broadcast:
 			return Stream{BroadcastStream, ""}, nil
-		case BroadcastFriends:
+		case broadcastFriends:
 			return Stream{BroadcastFriendsStream, ""}, nil
-		case Like:
+		case like:
 			return Stream{LikeStream, ""}, nil
 		default:
 			return Stream{NoStream, ""}, fmt.Errorf("googlereader: unknown stream with id: %s", id)
 		}
-	case strings.HasPrefix(streamID, fmt.Sprintf(UserLabelPrefix, userID)) || strings.HasPrefix(streamID, LabelPrefix):
-		id := strings.TrimPrefix(streamID, fmt.Sprintf(UserLabelPrefix, userID))
-		id = strings.TrimPrefix(id, LabelPrefix)
+	case strings.HasPrefix(streamID, fmt.Sprintf(userLabelPrefix, userID)),
+		strings.HasPrefix(streamID, labelPrefix):
+		id := strings.TrimPrefix(streamID, fmt.Sprintf(userLabelPrefix, userID))
+		id = strings.TrimPrefix(id, labelPrefix)
 		return Stream{LabelStream, id}, nil
 	case streamID == "":
 		return Stream{NoStream, ""}, nil
@@ -107,7 +109,7 @@ func getStream(streamID string, userID int64) (Stream, error) {
 }
 
 func getStreams(streamIDs []string, userID int64) ([]Stream, error) {
-	streams := make([]Stream, 0)
+	streams := make([]Stream, 0, len(streamIDs))
 	for _, streamID := range streamIDs {
 		stream, err := getStream(streamID, userID)
 		if err != nil {