Update dependencies/vendor (#1659)
parent
658bdd9faa
commit
3893a035be
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
language: go
|
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.cache/go-build
|
|
||||||
- $HOME/gopath/pkg/mod
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.x
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
|
||||||
- git describe --tags $(git rev-list --tags --max-count=1) --always
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go test -v -race -coverprofile=coverage.txt -covermode=atomic -p=1 ./...
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
@ -1,125 +1,124 @@
|
|||||||
# VK SDK for Golang
|
# VK SDK for Golang
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.com/SevereCloud/vksdk.svg?branch=master)](https://travis-ci.com/SevereCloud/vksdk)
|
[![PkgGoDev](https://pkg.go.dev/badge/github.com/SevereCloud/vksdk/v2/v2)](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2?tab=subdirectories)
|
||||||
[![PkgGoDev](https://pkg.go.dev/badge/github.com/SevereCloud/vksdk/v2/v2)](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2?tab=subdirectories)
|
[![VK Developers](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/)
|
||||||
[![VK Developers](https://img.shields.io/badge/developers-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.com/dev/)
|
[![codecov](https://codecov.io/gh/SevereCloud/vksdk/branch/master/graph/badge.svg)](https://codecov.io/gh/SevereCloud/vksdk)
|
||||||
[![codecov](https://codecov.io/gh/SevereCloud/vksdk/branch/master/graph/badge.svg)](https://codecov.io/gh/SevereCloud/vksdk)
|
[![VK chat](https://img.shields.io/badge/VK%20chat-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.me/join/AJQ1d6Or8Q00Y_CSOESfbqGt)
|
||||||
[![VK chat](https://img.shields.io/badge/VK%20chat-%234a76a8.svg?logo=VK&logoColor=white)](https://vk.me/join/AJQ1d6Or8Q00Y_CSOESfbqGt)
|
[![release](https://img.shields.io/github/v/tag/SevereCloud/vksdk?label=release)](https://github.com/SevereCloud/vksdk/releases)
|
||||||
[![release](https://img.shields.io/github/v/tag/SevereCloud/vksdk?label=release)](https://github.com/SevereCloud/vksdk/releases)
|
[![license](https://img.shields.io/github/license/SevereCloud/vksdk.svg?maxAge=2592000)](https://github.com/SevereCloud/vksdk/blob/master/LICENSE)
|
||||||
[![license](https://img.shields.io/github/license/SevereCloud/vksdk.svg?maxAge=2592000)](https://github.com/SevereCloud/vksdk/blob/master/LICENSE)
|
|
||||||
|
**VK SDK for Golang** ready implementation of the main VK API functions for Go.
|
||||||
**VK SDK for Golang** ready implementation of the main VK API functions for Go.
|
|
||||||
|
[Russian documentation](https://github.com/SevereCloud/vksdk/wiki)
|
||||||
[Russian documentation](https://github.com/SevereCloud/vksdk/wiki)
|
|
||||||
|
## Features
|
||||||
## Features
|
|
||||||
|
Version API 5.131.
|
||||||
Version API 5.131.
|
|
||||||
|
- [API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/api)
|
||||||
- [API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/api)
|
- 400+ methods
|
||||||
- 400+ methods
|
- Ability to change the request handler
|
||||||
- Ability to change the request handler
|
- Ability to modify HTTP client
|
||||||
- Ability to modify HTTP client
|
- Request Limiter
|
||||||
- Request Limiter
|
- Token pool
|
||||||
- Token pool
|
- [Callback API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/callback)
|
||||||
- [Callback API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/callback)
|
- Tracking tool for users activity in your VK communities
|
||||||
- Tracking tool for users activity in your VK communities
|
- Supports all events
|
||||||
- Supports all events
|
- Auto setting callback
|
||||||
- Auto setting callback
|
- [Bots Long Poll API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/longpoll-bot)
|
||||||
- [Bots Long Poll API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/longpoll-bot)
|
- Allows you to work with community events in real time
|
||||||
- Allows you to work with community events in real time
|
- Supports all events
|
||||||
- Supports all events
|
- Ability to modify HTTP client
|
||||||
- Ability to modify HTTP client
|
- [User Long Poll API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/longpoll-user)
|
||||||
- [User Long Poll API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/longpoll-user)
|
- Allows you to work with user events in real time
|
||||||
- Allows you to work with user events in real time
|
- Ability to modify HTTP client
|
||||||
- Ability to modify HTTP client
|
- [Streaming API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/streaming)
|
||||||
- [Streaming API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/streaming)
|
- Receiving public data from VK by specified keywords
|
||||||
- Receiving public data from VK by specified keywords
|
- Ability to modify HTTP client
|
||||||
- Ability to modify HTTP client
|
- [FOAF](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/foaf)
|
||||||
- [FOAF](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/foaf)
|
- Machine-readable ontology describing persons
|
||||||
- Machine-readable ontology describing persons
|
- Works with users and groups
|
||||||
- Works with users and groups
|
- The only place to get page creation date
|
||||||
- The only place to get page creation date
|
- [Games](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/games)
|
||||||
- [Games](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/games)
|
- Checking launch parameters
|
||||||
- Checking launch parameters
|
- Intermediate http handler
|
||||||
- Intermediate http handler
|
- [VK Mini Apps](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/vkapps)
|
||||||
- [VK Mini Apps](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/vkapps)
|
- Checking launch parameters
|
||||||
- Checking launch parameters
|
- Intermediate http handler
|
||||||
- Intermediate http handler
|
- [Payments API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/payments)
|
||||||
- [Payments API](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/payments)
|
- Processes payment notifications
|
||||||
- Processes payment notifications
|
- [Marusia Skills](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/marusia)
|
||||||
- [Marusia Skills](https://pkg.go.dev/github.com/SevereCloud/vksdk/v2/marusia)
|
- For creating Marusia Skills
|
||||||
- For creating Marusia Skills
|
- Support SSML
|
||||||
- Support SSML
|
|
||||||
|
## Install
|
||||||
## Install
|
|
||||||
|
```bash
|
||||||
```bash
|
# go mod init mymodulename
|
||||||
# go mod init mymodulename
|
go get github.com/SevereCloud/vksdk/v2@latest
|
||||||
go get github.com/SevereCloud/vksdk/v2@latest
|
```
|
||||||
```
|
|
||||||
|
## Use by
|
||||||
## Use by
|
|
||||||
|
- [Joe](https://github.com/go-joe/joe) adapter: <https://github.com/tdakkota/joe-vk-adapter>
|
||||||
- [Joe](https://github.com/go-joe/joe) adapter: <https://github.com/tdakkota/joe-vk-adapter>
|
- [Logrus](https://github.com/sirupsen/logrus) hook: <https://github.com/SevereCloud/vkrus>
|
||||||
- [Logrus](https://github.com/sirupsen/logrus) hook: <https://github.com/SevereCloud/vkrus>
|
|
||||||
|
### Example
|
||||||
### Example
|
|
||||||
|
```go
|
||||||
```go
|
package main
|
||||||
package main
|
|
||||||
|
import (
|
||||||
import (
|
"context"
|
||||||
"context"
|
"log"
|
||||||
"log"
|
|
||||||
|
"github.com/SevereCloud/vksdk/v2/api"
|
||||||
"github.com/SevereCloud/vksdk/v2/api"
|
"github.com/SevereCloud/vksdk/v2/api/params"
|
||||||
"github.com/SevereCloud/vksdk/v2/api/params"
|
"github.com/SevereCloud/vksdk/v2/events"
|
||||||
"github.com/SevereCloud/vksdk/v2/events"
|
"github.com/SevereCloud/vksdk/v2/longpoll-bot"
|
||||||
"github.com/SevereCloud/vksdk/v2/longpoll-bot"
|
)
|
||||||
)
|
|
||||||
|
func main() {
|
||||||
func main() {
|
token := "<TOKEN>" // use os.Getenv("TOKEN")
|
||||||
token := "<TOKEN>" // use os.Getenv("TOKEN")
|
vk := api.NewVK(token)
|
||||||
vk := api.NewVK(token)
|
|
||||||
|
// get information about the group
|
||||||
// get information about the group
|
group, err := vk.GroupsGetByID(nil)
|
||||||
group, err := vk.GroupsGetByID(nil)
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal(err)
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
|
||||||
|
// Initializing Long Poll
|
||||||
// Initializing Long Poll
|
lp, err := longpoll.NewLongPoll(vk, group[0].ID)
|
||||||
lp, err := longpoll.NewLongPoll(vk, group[0].ID)
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal(err)
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
|
||||||
|
// New message event
|
||||||
// New message event
|
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
|
||||||
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
|
log.Printf("%d: %s", obj.Message.PeerID, obj.Message.Text)
|
||||||
log.Printf("%d: %s", obj.Message.PeerID, obj.Message.Text)
|
|
||||||
|
if obj.Message.Text == "ping" {
|
||||||
if obj.Message.Text == "ping" {
|
b := params.NewMessagesSendBuilder()
|
||||||
b := params.NewMessagesSendBuilder()
|
b.Message("pong")
|
||||||
b.Message("pong")
|
b.RandomID(0)
|
||||||
b.RandomID(0)
|
b.PeerID(obj.Message.PeerID)
|
||||||
b.PeerID(obj.Message.PeerID)
|
|
||||||
|
_, err := vk.MessagesSend(b.Params)
|
||||||
_, err := vk.MessagesSend(b.Params)
|
if err != nil {
|
||||||
if err != nil {
|
log.Fatal(err)
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
// Run Bots Long Poll
|
||||||
// Run Bots Long Poll
|
log.Println("Start Long Poll")
|
||||||
log.Println("Start Long Poll")
|
if err := lp.Run(); err != nil {
|
||||||
if err := lp.Run(); err != nil {
|
log.Fatal(err)
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
}
|
||||||
}
|
```
|
||||||
```
|
|
||||||
|
## LICENSE
|
||||||
## LICENSE
|
|
||||||
|
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FSevereCloud%2Fvksdk.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FSevereCloud%2Fvksdk?ref=badge_large)
|
||||||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FSevereCloud%2Fvksdk.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FSevereCloud%2Fvksdk?ref=badge_large)
|
|
||||||
|
@ -0,0 +1,103 @@
|
|||||||
|
package api // import "github.com/SevereCloud/vksdk/v2/api"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/SevereCloud/vksdk/v2/object"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MarusiaGetPictureUploadLinkResponse struct.
|
||||||
|
type MarusiaGetPictureUploadLinkResponse struct {
|
||||||
|
PictureUploadLink string `json:"picture_upload_link"` // Link
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaGetPictureUploadLink method.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaGetPictureUploadLink(params Params) (response MarusiaGetPictureUploadLinkResponse, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.getPictureUploadLink", &response, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaSavePictureResponse struct.
|
||||||
|
type MarusiaSavePictureResponse struct {
|
||||||
|
AppID int `json:"app_id"`
|
||||||
|
PhotoID int `json:"photo_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaSavePicture method.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaSavePicture(params Params) (response MarusiaSavePictureResponse, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.savePicture", &response, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaGetPicturesResponse struct.
|
||||||
|
type MarusiaGetPicturesResponse struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
Items []object.MarusiaPicture `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaGetPictures method.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaGetPictures(params Params) (response MarusiaGetPicturesResponse, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.getPictures", &response, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaDeletePicture delete picture.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaDeletePicture(params Params) (response int, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.deletePicture", &response, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaGetAudioUploadLinkResponse struct.
|
||||||
|
type MarusiaGetAudioUploadLinkResponse struct {
|
||||||
|
AudioUploadLink string `json:"audio_upload_link"` // Link
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaGetAudioUploadLink method.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaGetAudioUploadLink(params Params) (response MarusiaGetAudioUploadLinkResponse, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.getAudioUploadLink", &response, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaCreateAudioResponse struct.
|
||||||
|
type MarusiaCreateAudioResponse struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaCreateAudio method.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaCreateAudio(params Params) (response MarusiaCreateAudioResponse, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.createAudio", &response, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaGetAudiosResponse struct.
|
||||||
|
type MarusiaGetAudiosResponse struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
Audios []object.MarusiaAudio `json:"audios"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaGetAudios method.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaGetAudios(params Params) (response MarusiaGetAudiosResponse, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.getAudios", &response, params)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaDeleteAudio delete audio.
|
||||||
|
//
|
||||||
|
// https://vk.com/dev/marusia_skill_docs10
|
||||||
|
func (vk *VK) MarusiaDeleteAudio(params Params) (response int, err error) {
|
||||||
|
err = vk.RequestUnmarshal("marusia.deleteAudio", &response, params)
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package object // import "github.com/SevereCloud/vksdk/v2/object"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MarusiaPicture struct.
|
||||||
|
type MarusiaPicture struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
OwnerID int `json:"owner_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaPictureUploadResponse struct.
|
||||||
|
type MarusiaPictureUploadResponse struct {
|
||||||
|
Hash string `json:"hash"` // Uploading hash
|
||||||
|
Photo json.RawMessage `json:"photo"` // Uploaded photo data
|
||||||
|
Server int `json:"server"` // Upload server number
|
||||||
|
AID int `json:"aid"`
|
||||||
|
MessageCode int `json:"message_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaAudio struct.
|
||||||
|
type MarusiaAudio struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
OwnerID int `json:"owner_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaAudioUploadResponse struct.
|
||||||
|
type MarusiaAudioUploadResponse struct {
|
||||||
|
Sha string `json:"sha"`
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Meta MarusiaAudioMeta `json:"meta"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Server string `json:"server"`
|
||||||
|
UserID int `json:"user_id"`
|
||||||
|
RequestID string `json:"request_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarusiaAudioMeta struct.
|
||||||
|
type MarusiaAudioMeta struct {
|
||||||
|
Album string `json:"album"`
|
||||||
|
Artist string `json:"artist"`
|
||||||
|
Bitrate string `json:"bitrate"`
|
||||||
|
Duration string `json:"duration"`
|
||||||
|
Genre string `json:"genre"`
|
||||||
|
Kad string `json:"kad"`
|
||||||
|
Md5 string `json:"md5"`
|
||||||
|
Md5DataSize string `json:"md5_data_size"`
|
||||||
|
Samplerate string `json:"samplerate"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
// Copyright 2021 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"database/sql/driver"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var jsonNull = []byte("null")
|
||||||
|
|
||||||
|
// NullUUID represents a UUID that may be null.
|
||||||
|
// NullUUID implements the SQL driver.Scanner interface so
|
||||||
|
// it can be used as a scan destination:
|
||||||
|
//
|
||||||
|
// var u uuid.NullUUID
|
||||||
|
// err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&u)
|
||||||
|
// ...
|
||||||
|
// if u.Valid {
|
||||||
|
// // use u.UUID
|
||||||
|
// } else {
|
||||||
|
// // NULL value
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
type NullUUID struct {
|
||||||
|
UUID UUID
|
||||||
|
Valid bool // Valid is true if UUID is not NULL
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan implements the SQL driver.Scanner interface.
|
||||||
|
func (nu *NullUUID) Scan(value interface{}) error {
|
||||||
|
if value == nil {
|
||||||
|
nu.UUID, nu.Valid = Nil, false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err := nu.UUID.Scan(value)
|
||||||
|
if err != nil {
|
||||||
|
nu.Valid = false
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
nu.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value implements the driver Valuer interface.
|
||||||
|
func (nu NullUUID) Value() (driver.Value, error) {
|
||||||
|
if !nu.Valid {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
// Delegate to UUID Value function
|
||||||
|
return nu.UUID.Value()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalBinary implements encoding.BinaryMarshaler.
|
||||||
|
func (nu NullUUID) MarshalBinary() ([]byte, error) {
|
||||||
|
if nu.Valid {
|
||||||
|
return nu.UUID[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return []byte(nil), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalBinary implements encoding.BinaryUnmarshaler.
|
||||||
|
func (nu *NullUUID) UnmarshalBinary(data []byte) error {
|
||||||
|
if len(data) != 16 {
|
||||||
|
return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
|
||||||
|
}
|
||||||
|
copy(nu.UUID[:], data)
|
||||||
|
nu.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalText implements encoding.TextMarshaler.
|
||||||
|
func (nu NullUUID) MarshalText() ([]byte, error) {
|
||||||
|
if nu.Valid {
|
||||||
|
return nu.UUID.MarshalText()
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonNull, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||||
|
func (nu *NullUUID) UnmarshalText(data []byte) error {
|
||||||
|
id, err := ParseBytes(data)
|
||||||
|
if err != nil {
|
||||||
|
nu.Valid = false
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
nu.UUID = id
|
||||||
|
nu.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements json.Marshaler.
|
||||||
|
func (nu NullUUID) MarshalJSON() ([]byte, error) {
|
||||||
|
if nu.Valid {
|
||||||
|
return json.Marshal(nu.UUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonNull, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements json.Unmarshaler.
|
||||||
|
func (nu *NullUUID) UnmarshalJSON(data []byte) error {
|
||||||
|
if bytes.Equal(data, jsonNull) {
|
||||||
|
*nu = NullUUID{}
|
||||||
|
return nil // valid null UUID
|
||||||
|
}
|
||||||
|
err := json.Unmarshal(data, &nu.UUID)
|
||||||
|
nu.Valid = err == nil
|
||||||
|
return err
|
||||||
|
}
|
@ -1,67 +0,0 @@
|
|||||||
language: go
|
|
||||||
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- osx
|
|
||||||
- windows
|
|
||||||
|
|
||||||
arch:
|
|
||||||
- amd64
|
|
||||||
- arm64
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.13.x
|
|
||||||
- 1.14.x
|
|
||||||
- 1.15.x
|
|
||||||
- 1.16.x
|
|
||||||
- master
|
|
||||||
|
|
||||||
env:
|
|
||||||
- CGO_ENABLED=0
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go vet ./...
|
|
||||||
- go test -test.v -test.run ^TestCPUID$
|
|
||||||
- CGO_ENABLED=1 go test -race ./...
|
|
||||||
- go test -tags=nounsafe -test.v -test.run ^TestCPUID$
|
|
||||||
- go test -tags=noasm ./...
|
|
||||||
- go run ./cmd/cpuid/main.go
|
|
||||||
- go run ./cmd/cpuid/main.go -json
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
allow_failures:
|
|
||||||
- go: 'master'
|
|
||||||
fast_finish: true
|
|
||||||
include:
|
|
||||||
- stage: other
|
|
||||||
go: 1.16.x
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
script:
|
|
||||||
- diff <(gofmt -d .) <(printf "")
|
|
||||||
- diff <(gofmt -d ./private) <(printf "")
|
|
||||||
- curl -sfL https://git.io/goreleaser | VERSION=v0.157.0 sh -s -- check # check goreleaser config for deprecations
|
|
||||||
- curl -sL https://git.io/goreleaser | VERSION=v0.157.0 sh -s -- --snapshot --skip-publish --rm-dist
|
|
||||||
- go get github.com/klauspost/asmfmt&&go install github.com/klauspost/asmfmt/cmd/asmfmt
|
|
||||||
- diff <(asmfmt -d .) <(printf "")
|
|
||||||
- GOOS=linux GOARCH=386 go test .
|
|
||||||
- ./test-architectures.sh
|
|
||||||
- stage: other
|
|
||||||
go: 1.15.x
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
script:
|
|
||||||
- ./test-architectures.sh
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
- provider: script
|
|
||||||
skip_cleanup: true
|
|
||||||
script: curl -sL https://git.io/goreleaser | VERSION=v0.157.0 bash || true
|
|
||||||
on:
|
|
||||||
tags: true
|
|
||||||
condition: ($TRAVIS_OS_NAME = linux) && ($TRAVIS_CPU_ARCH = amd64)
|
|
||||||
go: 1.16.x
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
|
|
@ -0,0 +1,28 @@
|
|||||||
|
package logr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Buffer provides a thread-safe buffer useful for logging to memory in unit tests.
|
||||||
|
type Buffer struct {
|
||||||
|
buf bytes.Buffer
|
||||||
|
mux sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Buffer) Read(p []byte) (n int, err error) {
|
||||||
|
b.mux.Lock()
|
||||||
|
defer b.mux.Unlock()
|
||||||
|
return b.buf.Read(p)
|
||||||
|
}
|
||||||
|
func (b *Buffer) Write(p []byte) (n int, err error) {
|
||||||
|
b.mux.Lock()
|
||||||
|
defer b.mux.Unlock()
|
||||||
|
return b.buf.Write(p)
|
||||||
|
}
|
||||||
|
func (b *Buffer) String() string {
|
||||||
|
b.mux.Lock()
|
||||||
|
defer b.mux.Unlock()
|
||||||
|
return b.buf.String()
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package targets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/mattermost/logr/v2"
|
||||||
|
"github.com/mattermost/logr/v2/formatters"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Testing is a simple log target that writes to a (*testing.T) log.
|
||||||
|
type Testing struct {
|
||||||
|
mux sync.Mutex
|
||||||
|
t *testing.T
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTestingTarget(t *testing.T) *Testing {
|
||||||
|
return &Testing{
|
||||||
|
t: t,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init is called once to initialize the target.
|
||||||
|
func (tt *Testing) Init() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write outputs bytes to this file target.
|
||||||
|
func (tt *Testing) Write(p []byte, rec *logr.LogRec) (int, error) {
|
||||||
|
tt.mux.Lock()
|
||||||
|
defer tt.mux.Unlock()
|
||||||
|
|
||||||
|
if tt.t != nil {
|
||||||
|
s := strings.TrimSpace(string(p))
|
||||||
|
tt.t.Log(s)
|
||||||
|
}
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shutdown is called once to free/close any resources.
|
||||||
|
// Target queue is already drained when this is called.
|
||||||
|
func (tt *Testing) Shutdown() error {
|
||||||
|
tt.mux.Lock()
|
||||||
|
defer tt.mux.Unlock()
|
||||||
|
|
||||||
|
tt.t = nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTestLogger creates a logger for unit tests. Log records are output to `(*testing.T).Log`.
|
||||||
|
// A new logger is returned along with a method to shutdown the new logger.
|
||||||
|
func CreateTestLogger(t *testing.T, levels ...logr.Level) (logger logr.Logger, shutdown func() error) {
|
||||||
|
lgr, _ := logr.New()
|
||||||
|
filter := logr.NewCustomFilter(levels...)
|
||||||
|
formatter := &formatters.Plain{EnableCaller: true}
|
||||||
|
target := NewTestingTarget(t)
|
||||||
|
|
||||||
|
if err := lgr.AddTarget(target, "test", filter, formatter, 1000); err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
shutdown = func() error {
|
||||||
|
err := lgr.Shutdown()
|
||||||
|
if err != nil {
|
||||||
|
target.mux.Lock()
|
||||||
|
target.t.Error("error shutting down test logger", err)
|
||||||
|
target.mux.Unlock()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return lgr.NewLogger(), shutdown
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
language: go
|
|
||||||
sudo: false
|
|
||||||
go:
|
|
||||||
- 1.13.x
|
|
||||||
- tip
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- go get -t -v ./...
|
|
||||||
|
|
||||||
script:
|
|
||||||
- ./go.test.sh
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
||||||
|
|
@ -0,0 +1,182 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
|
||||||
|
* (C) 2018-2021 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package minio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/xml"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||||
|
"github.com/minio/minio-go/v7/pkg/tags"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RestoreType represents the restore request type
|
||||||
|
type RestoreType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// RestoreSelect represents the restore SELECT operation
|
||||||
|
RestoreSelect = RestoreType("SELECT")
|
||||||
|
)
|
||||||
|
|
||||||
|
// TierType represents a retrieval tier
|
||||||
|
type TierType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// TierStandard is the standard retrieval tier
|
||||||
|
TierStandard = TierType("Standard")
|
||||||
|
// TierBulk is the bulk retrieval tier
|
||||||
|
TierBulk = TierType("Bulk")
|
||||||
|
// TierExpedited is the expedited retrieval tier
|
||||||
|
TierExpedited = TierType("Expedited")
|
||||||
|
)
|
||||||
|
|
||||||
|
// GlacierJobParameters represents the retrieval tier parameter
|
||||||
|
type GlacierJobParameters struct {
|
||||||
|
Tier TierType
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encryption contains the type of server-side encryption used during object retrieval
|
||||||
|
type Encryption struct {
|
||||||
|
EncryptionType string
|
||||||
|
KMSContext string
|
||||||
|
KMSKeyID string `xml:"KMSKeyId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MetadataEntry represents a metadata information of the restored object.
|
||||||
|
type MetadataEntry struct {
|
||||||
|
Name string
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
|
// S3 holds properties of the copy of the archived object
|
||||||
|
type S3 struct {
|
||||||
|
AccessControlList *AccessControlList `xml:"AccessControlList,omiempty"`
|
||||||
|
BucketName string
|
||||||
|
Prefix string
|
||||||
|
CannedACL *string `xml:"CannedACL,omitempty"`
|
||||||
|
Encryption *Encryption `xml:"Encryption,omitempty"`
|
||||||
|
StorageClass *string `xml:"StorageClass,omitempty"`
|
||||||
|
Tagging *tags.Tags `xml:"Tagging,omitempty"`
|
||||||
|
UserMetadata *MetadataEntry `xml:"UserMetadata,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectParameters holds the select request parameters
|
||||||
|
type SelectParameters struct {
|
||||||
|
XMLName xml.Name `xml:"SelectParameters"`
|
||||||
|
ExpressionType QueryExpressionType
|
||||||
|
Expression string
|
||||||
|
InputSerialization SelectObjectInputSerialization
|
||||||
|
OutputSerialization SelectObjectOutputSerialization
|
||||||
|
}
|
||||||
|
|
||||||
|
// OutputLocation holds properties of the copy of the archived object
|
||||||
|
type OutputLocation struct {
|
||||||
|
XMLName xml.Name `xml:"OutputLocation"`
|
||||||
|
S3 S3 `xml:"S3"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreRequest holds properties of the restore object request
|
||||||
|
type RestoreRequest struct {
|
||||||
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ RestoreRequest"`
|
||||||
|
Type *RestoreType `xml:"Type,omitempty"`
|
||||||
|
Tier *TierType `xml:"Tier,omitempty"`
|
||||||
|
Days *int `xml:"Days,omitempty"`
|
||||||
|
GlacierJobParameters *GlacierJobParameters `xml:"GlacierJobParameters,omitempty"`
|
||||||
|
Description *string `xml:"Description,omitempty"`
|
||||||
|
SelectParameters *SelectParameters `xml:"SelectParameters,omitempty"`
|
||||||
|
OutputLocation *OutputLocation `xml:"OutputLocation,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDays sets the days parameter of the restore request
|
||||||
|
func (r *RestoreRequest) SetDays(v int) {
|
||||||
|
r.Days = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDays sets the GlacierJobParameters of the restore request
|
||||||
|
func (r *RestoreRequest) SetGlacierJobParameters(v GlacierJobParameters) {
|
||||||
|
r.GlacierJobParameters = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetType sets the type of the restore request
|
||||||
|
func (r *RestoreRequest) SetType(v RestoreType) {
|
||||||
|
r.Type = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTier sets the retrieval tier of the restore request
|
||||||
|
func (r *RestoreRequest) SetTier(v TierType) {
|
||||||
|
r.Tier = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the description of the restore request
|
||||||
|
func (r *RestoreRequest) SetDescription(v string) {
|
||||||
|
r.Description = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSelectParameters sets SelectParameters of the restore select request
|
||||||
|
func (r *RestoreRequest) SetSelectParameters(v SelectParameters) {
|
||||||
|
r.SelectParameters = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOutputLocation sets the properties of the copy of the archived object
|
||||||
|
func (r *RestoreRequest) SetOutputLocation(v OutputLocation) {
|
||||||
|
r.OutputLocation = &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreObject is a implementation of https://docs.aws.amazon.com/AmazonS3/latest/API/API_RestoreObject.html AWS S3 API
|
||||||
|
func (c Client) RestoreObject(ctx context.Context, bucketName, objectName, versionID string, req RestoreRequest) error {
|
||||||
|
// Input validation.
|
||||||
|
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := s3utils.CheckValidObjectName(objectName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
restoreRequestBytes, err := xml.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
urlValues := make(url.Values)
|
||||||
|
urlValues.Set("restore", "")
|
||||||
|
if versionID != "" {
|
||||||
|
urlValues.Set("versionId", versionID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute POST on bucket/object.
|
||||||
|
resp, err := c.executeMethod(ctx, http.MethodPost, requestMetadata{
|
||||||
|
bucketName: bucketName,
|
||||||
|
objectName: objectName,
|
||||||
|
queryValues: urlValues,
|
||||||
|
contentMD5Base64: sumMD5Base64(restoreRequestBytes),
|
||||||
|
contentSHA256Hex: sum256Hex(restoreRequestBytes),
|
||||||
|
contentBody: bytes.NewReader(restoreRequestBytes),
|
||||||
|
contentLength: int64(len(restoreRequestBytes)),
|
||||||
|
})
|
||||||
|
defer closeResponse(resp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusAccepted {
|
||||||
|
return httpRespToErrorResponse(resp, bucketName, "")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -1,15 +1,9 @@
|
|||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/modern-go/concurrent"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "e0a39a4cb4216ea8db28e22a69f4ec25610d513a"
|
|
||||||
version = "1.0.0"
|
|
||||||
|
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "daee8a88b3498b61c5640056665b8b9eea062006f5e596bbb6a3ed9119a11ec7"
|
input-imports = []
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
//+build go1.18
|
||||||
|
|
||||||
|
package reflect2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// m escapes into the return value, but the caller of mapiterinit
|
||||||
|
// doesn't let the return value escape.
|
||||||
|
//go:noescape
|
||||||
|
//go:linkname mapiterinit reflect.mapiterinit
|
||||||
|
func mapiterinit(rtype unsafe.Pointer, m unsafe.Pointer, it *hiter)
|
||||||
|
|
||||||
|
func (type2 *UnsafeMapType) UnsafeIterate(obj unsafe.Pointer) MapIterator {
|
||||||
|
var it hiter
|
||||||
|
mapiterinit(type2.rtype, *(*unsafe.Pointer)(obj), &it)
|
||||||
|
return &UnsafeMapIterator{
|
||||||
|
hiter: &it,
|
||||||
|
pKeyRType: type2.pKeyRType,
|
||||||
|
pElemRType: type2.pElemRType,
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
//+build go1.7
|
|
||||||
|
|
||||||
package reflect2
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
//go:linkname resolveTypeOff reflect.resolveTypeOff
|
|
||||||
func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer
|
|
@ -0,0 +1,21 @@
|
|||||||
|
//+build !go1.18
|
||||||
|
|
||||||
|
package reflect2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// m escapes into the return value, but the caller of mapiterinit
|
||||||
|
// doesn't let the return value escape.
|
||||||
|
//go:noescape
|
||||||
|
//go:linkname mapiterinit reflect.mapiterinit
|
||||||
|
func mapiterinit(rtype unsafe.Pointer, m unsafe.Pointer) (val *hiter)
|
||||||
|
|
||||||
|
func (type2 *UnsafeMapType) UnsafeIterate(obj unsafe.Pointer) MapIterator {
|
||||||
|
return &UnsafeMapIterator{
|
||||||
|
hiter: mapiterinit(type2.rtype, *(*unsafe.Pointer)(obj)),
|
||||||
|
pKeyRType: type2.pKeyRType,
|
||||||
|
pElemRType: type2.pElemRType,
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue