From f4997d3c823133c1445b1685a414e55c3a803172 Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Mon, 6 Jan 2020 02:16:52 +0300 Subject: [PATCH] docs: golint fix --- README.md | 58 ++++++++++++++++++++++++++++++------------ api/api.go | 1 + api/errors/errors.go | 4 +-- api/friends.go | 2 +- api/newsfeed.go | 2 +- api/params/account.go | 3 ++- api/params/ads.go | 2 +- api/params/apps.go | 3 ++- api/params/board.go | 4 +-- api/params/database.go | 4 +-- api/params/friends.go | 14 +++++----- api/params/groups.go | 2 +- api/params/market.go | 4 +-- api/params/video.go | 4 +-- api/podcasts.go | 24 ++++++++--------- api/upload.go | 2 +- object/appwidgets.go | 2 +- object/docs.go | 2 +- object/handler.go | 1 + vkapps/verify.go | 2 +- 20 files changed, 85 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index f96c17e6..be0a8b3b 100644 --- a/README.md +++ b/README.md @@ -47,26 +47,52 @@ go get github.com/SevereCloud/vksdk@latest package main import ( - "log" + "log" - "github.com/SevereCloud/vksdk/api" + "github.com/SevereCloud/vksdk/api" + "github.com/SevereCloud/vksdk/api/params" + "github.com/SevereCloud/vksdk/longpoll-bot" + "github.com/SevereCloud/vksdk/object" ) func main() { - vk := api.Init("") // рекомендуется использовать os.Getenv("TOKEN") - - params := api.Params{ - "user_ids": 1 - } - - users, err := vk.UsersGet(params) - if err != nil { - log.Fatal(err) - } - - for _, user := range users { - log.Printf("Пользователя с id%d зовут %s %s\n", user.ID, user.FirstName, user.LastName) - } + token := "" // рекомендуется использовать os.Getenv("TOKEN") + vk := api.Init(token) + + // Получаем информацию о группе + group, err := vk.GroupsGetByID(api.Params{}) + if err != nil { + log.Fatal(err) + } + + // Иницилизируем longpoll + lp, err := longpoll.Init(vk, group[0].ID) + if err != nil { + log.Fatal(err) + } + + // Событие нового сообщения + lp.MessageNew(func(obj object.MessageNewObject, groupID int) { + log.Printf("%d: %s", obj.Message.PeerID, obj.Message.Text) + + if obj.Message.Text == "ping" { + b := params.NewMessagesSendBuilder() + b.Message("pong") + b.RandomID(0) + b.PeerID(obj.Message.PeerID) + + _, err := vk.MessagesSend(b.Params) + if err != nil { + log.Fatal(err) + } + } + }) + + // Запускаем Bots Longpoll + log.Println("Start longpoll") + if err := lp.Run(); err != nil { + log.Fatal(err) + } } ``` diff --git a/api/api.go b/api/api.go index 33f4b7fc..8f19408c 100644 --- a/api/api.go +++ b/api/api.go @@ -14,6 +14,7 @@ import ( "github.com/SevereCloud/vksdk/object" ) +// Api constants const ( Version = "5.103" APIMethodURL = "https://api.vk.com/method/" diff --git a/api/errors/errors.go b/api/errors/errors.go index 511a19b1..4689bad5 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -287,7 +287,7 @@ func (errorType ErrorType) New(msg string) error { return customError{errorType: errorType, originalError: errors.New(msg)} } -// New creates a new customError with formatted message +// Newf creates a new customError with formatted message func (errorType ErrorType) Newf(msg string, args ...interface{}) error { return customError{errorType: errorType, originalError: fmt.Errorf(msg, args...)} } @@ -297,7 +297,7 @@ func (errorType ErrorType) Wrap(err error, msg string) error { return errorType.Wrapf(err, msg) } -// Wrap creates a new wrapped error with formatted message +// Wrapf creates a new wrapped error with formatted message func (errorType ErrorType) Wrapf(err error, msg string, args ...interface{}) error { return customError{errorType: errorType, originalError: errors.Wrapf(err, msg, args...)} } diff --git a/api/friends.go b/api/friends.go index 215f9b1a..139e5030 100644 --- a/api/friends.go +++ b/api/friends.go @@ -178,7 +178,7 @@ func (vk *VK) FriendsGetOnline(params Params) (response []int, err error) { return } -// FriendsGetOnlineResponse struct +// FriendsGetOnlineOnlineMobileResponse struct type FriendsGetOnlineOnlineMobileResponse struct { Online []int `json:"online"` OnlineMobile []int `json:"online_mobile"` diff --git a/api/newsfeed.go b/api/newsfeed.go index ef2da9e3..8b2993f5 100644 --- a/api/newsfeed.go +++ b/api/newsfeed.go @@ -161,7 +161,7 @@ func (vk *VK) NewsfeedGetSuggestedSources(params Params) (response NewsfeedGetSu return } -// NewsfeedIgnoreItemHides an item from the newsfeed. +// NewsfeedIgnoreItem Hides an item from the newsfeed. // // https://vk.com/dev/newsfeed.ignoreItem func (vk *VK) NewsfeedIgnoreItem(params Params) (response int, err error) { diff --git a/api/params/account.go b/api/params/account.go index 45e994e0..4883d586 100644 --- a/api/params/account.go +++ b/api/params/account.go @@ -475,9 +475,10 @@ func (b *AccountSetSilenceModeBuilder) PeerID(v int) { b.Params["peer_id"] = v } -// Sound +// Sound parameter // // * 1 — to enable sound in this dialog, +// // * 0 — to disable sound. Only if 'peer_id' contains user or community ID. func (b *AccountSetSilenceModeBuilder) Sound(v int) { b.Params["sound"] = v diff --git a/api/params/ads.go b/api/params/ads.go index 521139c6..175c9858 100644 --- a/api/params/ads.go +++ b/api/params/ads.go @@ -910,7 +910,7 @@ func (b *AdsGetTargetGroupsBuilder) ClientID(v int) { b.Params["client_id"] = v } -// Extended +// Extended parameter // // * 1 — to return pixel code. func (b *AdsGetTargetGroupsBuilder) Extended(v bool) { diff --git a/api/params/apps.go b/api/params/apps.go index d5b4179b..fb3a5f5b 100644 --- a/api/params/apps.go +++ b/api/params/apps.go @@ -163,7 +163,8 @@ func (b *AppsGetCatalogBuilder) Platform(v string) { b.Params["platform"] = v } -// Extended +// Extended parameter +// // * 1 — to return additional fields 'screenshots', 'MAU', 'catalog_position', and 'international'. // If set, 'count' must be less than or equal to '100'. // diff --git a/api/params/board.go b/api/params/board.go index 4bd6a3a1..2161a8ca 100644 --- a/api/params/board.go +++ b/api/params/board.go @@ -383,7 +383,7 @@ func (b *BoardGetTopicsBuilder) Count(v int) { b.Params["count"] = v } -// Extended +// Extended parameter // // * 1 — to return information about users who created topics or who posted there last, // @@ -392,7 +392,7 @@ func (b *BoardGetTopicsBuilder) Extended(v bool) { b.Params["extended"] = v } -// Preview +// Preview parameter // // * 1 — to return the first comment in each topic; // diff --git a/api/params/database.go b/api/params/database.go index 4c060d05..41d22b5e 100644 --- a/api/params/database.go +++ b/api/params/database.go @@ -62,7 +62,7 @@ func (b *DatabaseGetCitiesBuilder) Q(v string) { b.Params["q"] = v } -// NeedAll +// NeedAll parameter // // * 1 — to return all cities in the country, // @@ -114,7 +114,7 @@ func NewDatabaseGetCountriesBuilder() *DatabaseGetCountriesBuilder { return &DatabaseGetCountriesBuilder{api.Params{}} } -// NeedAll +// NeedAll parameter // // * 1 — to return a full list of all countries, // diff --git a/api/params/friends.go b/api/params/friends.go index 5ad1bae4..3aeb3620 100644 --- a/api/params/friends.go +++ b/api/params/friends.go @@ -76,7 +76,7 @@ func (b *FriendsAreFriendsBuilder) UserIDs(v []int) { b.Params["user_ids"] = v } -// NeedSign +// NeedSign parameter // // * 1 — to return 'sign' field. 'sign' is md5("{id}_{user_id}_{friends_status}_{application_secret}"), // where id is current user ID. This field allows to check that data has not been modified by the client. @@ -309,7 +309,7 @@ func (b *FriendsGetListsBuilder) UserID(v int) { b.Params["user_id"] = v } -// ReturnSystem +// ReturnSystem parameter // // * 1 — to return system friend lists. By default: '0'. func (b *FriendsGetListsBuilder) ReturnSystem(v bool) { @@ -384,7 +384,7 @@ func (b *FriendsGetOnlineBuilder) ListID(v int) { b.Params["list_id"] = v } -// OnlineMobile +// OnlineMobile parameter // // * 1 — to return an additional 'online_mobile' field, '0' — (default), func (b *FriendsGetOnlineBuilder) OnlineMobile(v bool) { @@ -449,7 +449,7 @@ func (b *FriendsGetRequestsBuilder) Count(v int) { b.Params["count"] = v } -// Extended +// Extended parameter // // * 1 — to return response messages from users who have sent a friend request or, // if 'suggested' is set to '1', to return a list of suggested friends @@ -457,14 +457,14 @@ func (b *FriendsGetRequestsBuilder) Extended(v bool) { b.Params["extended"] = v } -// NeedMutual +// NeedMutual parameter // // * 1 — to return a list of mutual friends (up to 20), if any func (b *FriendsGetRequestsBuilder) NeedMutual(v bool) { b.Params["need_mutual"] = v } -// Out +// Out parameter // // * 1 — to return outgoing requests, '0' — to return incoming requests (default) func (b *FriendsGetRequestsBuilder) Out(v bool) { @@ -483,7 +483,7 @@ func (b *FriendsGetRequestsBuilder) NeedViewed(v bool) { b.Params["need_viewed"] = v } -// Suggested +// Suggested parameter // // * 1 — to return a list of suggested friends, '0' — to return friend requests (default) func (b *FriendsGetRequestsBuilder) Suggested(v bool) { diff --git a/api/params/groups.go b/api/params/groups.go index cb39b38a..6dcb5fe5 100644 --- a/api/params/groups.go +++ b/api/params/groups.go @@ -989,7 +989,7 @@ func (b *GroupsGetBuilder) UserID(v int) { b.Params["user_id"] = v } -// Extended +// Extended parameter // // * 1 — to return complete information about a user's communities, // diff --git a/api/params/market.go b/api/params/market.go index fa9b4ad4..8631b77b 100644 --- a/api/params/market.go +++ b/api/params/market.go @@ -441,7 +441,7 @@ func (b *MarketGetBuilder) Offset(v int) { b.Params["offset"] = v } -// Extended +// Extended parameter // // * 1 – method will return additional fields: 'likes, can_comment, car_repost, photos'. // These parameters are not returned by default. @@ -601,7 +601,7 @@ func (b *MarketGetCommentsBuilder) Sort(v string) { b.Params["sort"] = v } -// Extended +// Extended parameter // // * 1 — comments will be returned as numbered objects, in addition lists of // 'profiles' and 'groups' objects will be returned. diff --git a/api/params/video.go b/api/params/video.go index b460c340..b9a1701f 100644 --- a/api/params/video.go +++ b/api/params/video.go @@ -870,7 +870,7 @@ func (b *VideoSaveBuilder) Description(v string) { b.Params["description"] = v } -// IsPrivate +// IsPrivate parameter // // * 1 — to designate the video as private (send it via a private message), the video will not appear // on the user's video list and will not be available by ID for other users, @@ -880,7 +880,7 @@ func (b *VideoSaveBuilder) IsPrivate(v bool) { b.Params["is_private"] = v } -// Wallpost +// Wallpost parameter // // * 1 — to post the saved video on a user's wall // * 0 — not to post the saved video on a user's wall diff --git a/api/podcasts.go b/api/podcasts.go index 44533f47..0e6824b2 100644 --- a/api/podcasts.go +++ b/api/podcasts.go @@ -9,9 +9,9 @@ type PodcastsGetCatalogResponse struct { Items []object.PodcastsItem `json:"items"` } -// PodcastsGetCatalog +// PodcastsGetCatalog method // -// extended=0 method +// extended=0 // // https://vk.com/dev/podcasts.getCatalog func (vk *VK) PodcastsGetCatalog(params Params) (response PodcastsGetCatalogResponse, err error) { @@ -27,9 +27,9 @@ type PodcastsGetCatalogExtendedResponse struct { object.ExtendedResponse } -// PodcastsGetCatalogExtended +// PodcastsGetCatalogExtended method // -// extended=1 method +// extended=1 // // https://vk.com/dev/podcasts.getCatalog func (vk *VK) PodcastsGetCatalogExtended(params Params) (response PodcastsGetCatalogExtendedResponse, err error) { @@ -70,9 +70,9 @@ type PodcastsGetFeedResponse struct { NextFrom string `json:"next_from"` } -// PodcastsGetFeed +// PodcastsGetFeed method // -// extended=0 method +// extended=0 // // https://vk.com/dev/podcasts.getFeed func (vk *VK) PodcastsGetFeed(params Params) (response PodcastsGetFeedResponse, err error) { @@ -89,9 +89,9 @@ type PodcastsGetFeedExtendedResponse struct { object.ExtendedResponse } -// PodcastsGetFeedExtended +// PodcastsGetFeedExtended method // -// extended=1 method +// extended=1 // // https://vk.com/dev/podcasts.getFeed func (vk *VK) PodcastsGetFeedExtended(params Params) (response PodcastsGetFeedExtendedResponse, err error) { @@ -118,9 +118,9 @@ type PodcastsGetStartPageResponse struct { } `json:"catalog"` } -// PodcastsGetStartPage +// PodcastsGetStartPage method // -// extended=0 method +// extended=0 // // https://vk.com/dev/podcasts.getStartPage func (vk *VK) PodcastsGetStartPage(params Params) (response PodcastsGetStartPageResponse, err error) { @@ -148,9 +148,9 @@ type PodcastsGetStartPageExtendedResponse struct { object.ExtendedResponse } -// PodcastsGetStartPageExtended +// PodcastsGetStartPageExtended method // -// extended=1 method +// extended=1 // // https://vk.com/dev/podcasts.getStartPage func (vk *VK) PodcastsGetStartPageExtended(params Params) (response PodcastsGetStartPageExtendedResponse, err error) { diff --git a/api/upload.go b/api/upload.go index 11627a72..2e1735f6 100644 --- a/api/upload.go +++ b/api/upload.go @@ -634,7 +634,7 @@ func (vk *VK) UploadMessagesDoc(peerID int, typeDoc, title, tags string, file io return } -// UploadOwneCoverrPhoto uploading a Main Photo to a Group Chat +// UploadOwnerCoverPhoto uploading a Main Photo to a Group Chat // // Supported formats: JPG, PNG, GIF. // diff --git a/object/appwidgets.go b/object/appwidgets.go index a3c12ad8..92767c7a 100644 --- a/object/appwidgets.go +++ b/object/appwidgets.go @@ -12,7 +12,7 @@ type AppWidgetsGroupImageUploadResponse struct { Hash string `json:"hash"` } -// AppWidgetsImagestruct +// AppWidgetsImage struct type AppWidgetsImage struct { ID string `json:"id"` Type string `json:"type"` diff --git a/object/docs.go b/object/docs.go index f4d53469..d9075a0d 100644 --- a/object/docs.go +++ b/object/docs.go @@ -54,7 +54,7 @@ type DocsDocPreviewGraffiti struct { Height int `json:"height"` } -// DocsDocPreviewVideo struct +// DocsDocPreviewVideo struct type DocsDocPreviewVideo struct { FileSize int `json:"file_size"` // Video file size in bites Height int `json:"height"` // Video's height in pixels diff --git a/object/handler.go b/object/handler.go index a33fb8af..80391769 100644 --- a/object/handler.go +++ b/object/handler.go @@ -14,6 +14,7 @@ type MessageNewObject struct { ClientInfo ClientInfo `json:"client_info"` } +// UnmarshalJSON func func (a *MessageNewObject) UnmarshalJSON(b []byte) (err error) { type r MessageNewObject diff --git a/vkapps/verify.go b/vkapps/verify.go index f6c3091d..fa5c59cd 100644 --- a/vkapps/verify.go +++ b/vkapps/verify.go @@ -74,7 +74,7 @@ func (pv *ParamsVerification) Verify(u *url.URL) (bool, error) { return base64Sign == values["sign"][0], nil } -// VerifyMiddleware +// VerifyMiddleware func func (pv *ParamsVerification) VerifyMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ok, err := pv.Verify(r.URL)