YAML конфиги в студию!
This commit is contained in:
parent
f240e35bbe
commit
1b4584ecd5
@ -9,3 +9,11 @@ vk-to-smtp
|
||||
|
||||
Зависимость: https://github.com/SevereCloud/vksdk/
|
||||
|
||||
UPD 2024-08-27: появилась такая вещь как конфиг! Кладется в /home/$USER/.config/vk-to-smtp.yaml, формата
|
||||
|
||||
```yaml
|
||||
VK:
|
||||
token: '123123123...'
|
||||
group_id: 'podvalsound'
|
||||
|
||||
```
|
1
go.mod
1
go.mod
@ -9,4 +9,5 @@ require (
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -23,5 +23,7 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
@ -2,11 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/SevereCloud/vksdk/v2/api"
|
||||
"github.com/SevereCloud/vksdk/v2/api/params"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
"github.com/SevereCloud/vksdk/v2/api"
|
||||
"github.com/SevereCloud/vksdk/v2/api/params"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -23,23 +25,51 @@ import (
|
||||
|
||||
*/
|
||||
|
||||
type Config struct {
|
||||
VK struct {
|
||||
Token string `yaml:"token"`
|
||||
GroupId string `yaml:"group_id"`
|
||||
} `yaml:"VK"`
|
||||
}
|
||||
|
||||
func configRead(cfg *Config) {
|
||||
userConfigDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(userConfigDir, "vk-to-smtp.yaml")
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
os.Create(path)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
decoder := yaml.NewDecoder(f)
|
||||
err = decoder.Decode(cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Init: Get token and group id from ENV
|
||||
token := os.Getenv("vktoken")
|
||||
//groupId, err := strconv.Atoi(os.Getenv("vkgroupid"))
|
||||
//if err != nil {
|
||||
// log.Fatal(err)
|
||||
//}
|
||||
var cfg Config
|
||||
configRead(&cfg)
|
||||
|
||||
if cfg.VK.Token == "" {
|
||||
log.Fatal("token is empty")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
// Init VK
|
||||
vk := api.NewVK(token)
|
||||
vk := api.NewVK(cfg.VK.Token)
|
||||
|
||||
// Fill params for wallGet
|
||||
wallGetParams := params.NewWallGetBuilder()
|
||||
wallGetParams.Count(10)
|
||||
wallGetParams.Domain("podvalsound")
|
||||
wallGetParams.Domain(cfg.VK.GroupId)
|
||||
wallGetParams.Extended(true)
|
||||
//wallGetParams.OwnerID(groupId)
|
||||
|
||||
// Do WallGet
|
||||
posts, err := vk.WallGet(wallGetParams.Params)
|
||||
|
Loading…
Reference in New Issue
Block a user