Created
November 16, 2020 07:41
-
-
Save asim/10b96ed42e300959ec96e963ed4cc6e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package handler | |
import ( | |
"context" | |
"time" | |
"github.com/micro/dev/model" | |
"github.com/micro/go-micro/errors" | |
"github.com/micro/micro/v3/service/logger" | |
"github.com/micro/micro/v3/service/store" | |
proto "posts/proto" | |
"github.com/gosimple/slug" | |
) | |
type Posts struct { | |
db model.Model | |
idIndex model.Index | |
createdIndex model.Index | |
slugIndex model.Index | |
} | |
func NewPosts() *Posts { | |
createdIndex := model.ByEquality("created") | |
createdIndex.Order.Type = model.OrderTypeDesc | |
slugIndex := model.ByEquality("slug") | |
idIndex := model.ByEquality("id") | |
idIndex.Order.Type = model.OrderTypeUnordered | |
return &Posts{ | |
db: model.New( | |
store.DefaultStore, | |
"posts", | |
model.Indexes(slugIndex, createdIndex), | |
&model.ModelOptions{ | |
IdIndex: idIndex, | |
}, | |
), | |
createdIndex: createdIndex, | |
slugIndex: slugIndex, | |
idIndex: idIndex, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment