~alexwennerberg/twitterbots-go

54a11b72536e24f24d9a29474cefc14b5a3d40f4 — alex wennerberg 2 months ago e54d0de
Update loading config
1 files changed, 7 insertions(+), 10 deletions(-)

M main.go
M main.go => main.go +7 -10
@@ 2,17 2,19 @@ package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"github.com/dghubble/go-twitter/twitter"
	"github.com/dghubble/oauth1"
	"os"
	"path"
)

func main() {
	client, err := getCreds("soulstxt")
	fileName := flag.String("config", "", "config filepath")
	flag.Parse()
	fmt.Println("Loading config from", *fileName)
	client, err := getCreds(fileName)
	if err != nil {
		// temp
		panic(err)
	}
	_, _, err = client.Statuses.Update("just setting up my twttr", nil)


@@ 28,13 30,8 @@ type TwitterCreds struct {
	AccessSecret   string
}

func getCreds(serviceName string) (*twitter.Client, error) {
	home, err := os.UserHomeDir()
	if err != nil {
		return nil, err
	}
	fileName := path.Join(home, ".config", "twitter-creds", serviceName+".conf")
	file, err := os.Open(fileName)
func getCreds(configFilename *string) (*twitter.Client, error) {
	file, err := os.Open(*configFilename)
	if err != nil {
		return nil, err
	}