Beispiel #1
0
func DbConfig() (Db, error) {

	dbInfo := Db{}
	logErr := logger.GetErr()
	logSuc := logger.GetSuc()

	f, err := os.Open("db.xml")
	defer f.Close()

	if err != nil {
		logErr.Println("db open error ", err)
		return dbInfo, err
	}

	xmlData, err := ioutil.ReadAll(f)
	if err != nil {
		logErr.Println("read xml error  ", err)
		return dbInfo, err
	}

	err = xml.Unmarshal(xmlData, &dbInfo)
	if err != nil {
		logErr.Println("xml Unmarshal error ", err)
		return dbInfo, err
	}
	logSuc.Println("xml read succeed \n", dbInfo)

	return dbInfo, nil
}
Beispiel #2
0
func DbInit() (*sql.DB, error) {

	logErr := logger.GetErr()

	db_info, err := DbConfig()
	if err != nil {
		log.Println("Db config error ", err)
		return nil, err
	} else {
		log.Println("Db config suc")
	}

	dbCmd := db_info.User + ":" + db_info.Cert + "@/" + db_info.Database + "?charset=utf8"
	//	fmt.Println(dbCmd)

	db, err := sql.Open("mysql", dbCmd)
	if err != nil {
		logErr.Println("Db open failed ", err)
		return db, err
	} else {
		logSuc := logger.GetSuc()
		logSuc.Println("Db open success")
	}
	return db, nil
}
Beispiel #3
0
func GetDb() *sql.DB {
	db, err := DbInit()
	for i := 0; i < 20; i++ {
		if err != nil {
			logErr := logger.GetErr()
			logErr.Println("datebase open failed the ", i, "th times")
		} else {
			logSuc := logger.GetSuc()
			logSuc.Println("database open success the ", i, "th times")
			break
		}
		db, err = DbInit()
	}
	return db
}
Beispiel #4
0
	"github.com/gorilla/securecookie"
	"html/template"
	"logger"
	"net/http"
)

func Init() {
	ResultTypeInit()
	UserOnline = make(map[string]string)
}

var res_type_info ResultType
var logInfo = logger.GetInfo()
var logWar = logger.GetWar()
var logErr = logger.GetErr()
var logDeb = logger.GetSuc()

func RegisterHandler(w http.ResponseWriter, r *http.Request) {

	fmt.Println(r.Method)

	if r.Method == "GET" {
		reg_Info := Reg_Type_Info{
			IsHide:   "none",
			Info:     "",
			BackShow: false,
		}

		file, err := template.ParseFiles("../www/html/register.html")
		if err != nil {
			logErr.Println("ParseFile register.html failed")