Example #1
0
func main() {
	conf := goini.SetConfig("./config.ini")
	url := conf.GetValue("info", "Url")
	GetZhihuQuestionList(url + "?page=")
	fmt.Print(len(urlList))

}
Example #2
0
func NewDb() (db *sql.DB) {
	//载入config文件信息
	conf := goini.SetConfig("./config/conf.ini")
	dsn := conf.GetValue("mysql", "dsn")

	ndb := &Mysqlhelper{}
	return ndb.conn(dsn)
}
Example #3
0
func mid(m *martini.ClassicMartini) {
	//载入config文件信息
	conf := goini.SetConfig("./config/conf.ini")
	//port := conf.GetValue("route", "port")
	//m.RunOnAddr(":" + port)
	db := helper.NewDb()
	m.Map(conf)
	m.Map(db)

	//过滤器handle
	m.Use(func(c martini.Context, log *log.Logger) {
		log.Println("before a request")
		c.Next()
		log.Println("after a request")
	})
}
func DownloadBook(bookUrl, bookName string) {
	/*
	 *通过传入书籍的下载URL和书籍名称来下载书籍并命名
	 *获取配置文件里面的存放路径
	 *通过判断传入的下载URL地址结尾来判断文件名称是pdf/mobi/epub格式
	 *然后用http.Get访问书籍地址
	 *最后用io.Copy拷贝文件到本地
	 */
	conf := goini.SetConfig("./config.ini")
	category := conf.GetValue("info", "BookCategory")
	tempSavePath := conf.GetValue("info", "SavePath")
	bookType := conf.GetValue("info", "BookType")
	savePath := tempSavePath + "/" + category

	if _, err := os.Stat(tempSavePath); err != nil {
		os.Mkdir(tempSavePath, 0777)
		os.Mkdir(savePath, 0777)
	} else {
		os.Mkdir(savePath, 0777)
	}

	//判断传入的下载地址结尾是pdf/mobi/epub、用来区分文件类型
	var name string
	if strings.Contains(bookUrl, ".mobi") == true {
		name = ".mobi"
	} else if strings.Contains(bookUrl, ".epub") == true {
		name = ".epub"
	} else if strings.Contains(bookUrl, ".azw") == true {
		name = ".azw"
	} else {
		name = ".pdf"
	}

	//判断用户希望下载的书籍类型并下载保存到本地
	if name == bookType || name == ".pdf" {
		res, _ := http.Get(bookUrl)
		file, _ := os.Create(savePath + "/" + bookName + name)
		if res.Body != nil {
			defer res.Body.Close()
		}
		io.Copy(file, res.Body)
		fmt.Println("下载完成")

	}

}
Example #5
0
//use goini read the configuration file and connect the mysql database
func SetConfig(filename string) (*Model, error) {
	c := new(Model)
	conf := goini.SetConfig(filename)
	charset := conf.GetValue("database", "charset")
	username := conf.GetValue("database", "username")
	password := conf.GetValue("database", "password")
	hostname := conf.GetValue("database", "hostname")
	database := conf.GetValue("database", "database")
	port := conf.GetValue("database", "port")
	db, err := sql.Open("mysql", username+":"+password+"@tcp("+hostname+":"+port+")/"+database+"?charset="+charset)
	err = db.Ping()
	if err != nil {
		//if connect error then return the error message
		return c, err
	}
	c.db = db
	return c, err
}
Example #6
0
func CreateDBCon() {
	conf := goini.SetConfig("configuration.ini")
	dbtype := conf.GetValue("database", "dbtype")
	username := conf.GetValue("database", "username")
	password := conf.GetValue("database", "password")
	IP := conf.GetValue("database", "IP")
	port := conf.GetValue("database", "port")
	dbname := conf.GetValue("database", "dbname")

	var conn string = ""
	conn += username + ":" + password + "@tcp(" + IP + ":" + port + ")/" + dbname + "?charset=utf8"

	db, _ = sql.Open(dbtype, conn)

	db.SetMaxOpenConns(2000)
	db.SetMaxIdleConns(1000)
	db.Ping()
}
Example #7
0
func GetConf(subject, body string) {
	/*
	 *  用goini第三方库读取config.ini配置文件获取配置内容
	 *  用于发送邮件
	 *
	 */
	var receiveMail string
	conf := goini.SetConfig("./config.ini")
	mailHost := conf.GetValue("info", "MailHost")
	mailUser := conf.GetValue("info", "MailUser")
	mailPassword := conf.GetValue("info", "MailPassword")
	note := conf.GetValue("note", "Note")

	//判断用户的笔记软件类型
	if note == "evernote" {
		receiveMail = conf.GetValue("evernote", "ReceiveMail")
		notebook := conf.GetValue("evernote", "Notebook")
		subject += "@" + notebook
	} else if note == "wiz" {
		receiveMail = conf.GetValue("wiz", "ReceiveMail")
	} else if note == "onenote" {
		receiveMail = "*****@*****.**"
	} else if note == "youdao" {
		receiveMail = "*****@*****.**"
	}

	//调用发送邮件函数并传递参数
	fmt.Println("Save Note")
	err := SendToNote(
		mailUser,
		mailPassword,
		mailHost,
		receiveMail,
		subject,
		body,
	)
	if err != nil {
		fmt.Println("Save Note Error!")
		fmt.Println(err)
	} else {
		fmt.Println("Save Note Success!")
	}

}
func main() {
	conf := goini.SetConfig("./config.ini")
	category := conf.GetValue("info", "BookCategory")
	GetZi5PageUrl(category)

}
Example #9
0
import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/tealeg/xlsx"
	"github.com/widuu/goini"
	"io/ioutil"
	"log"
	"path/filepath"
	"runtime"
	"strings"
	"time"
)

// 获取配置
var conf = goini.SetConfig("./config.ini")

func main() {

	runtime.GOMAXPROCS(runtime.NumCPU())

	// path
	path := conf.GetValue("path", "path")

	files, _ := filepath.Glob(path + "*")
	isInsert := make(chan bool)
	filePath := make(chan string)
	tabName := make(chan string)

	log := ""
	fmt.Println("正在导出...")