Connecting to the database
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"myapp/internal/driver"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
@ -30,7 +31,7 @@ type config struct {
|
||||
|
||||
type application struct {
|
||||
config config
|
||||
infolog *log.Logger
|
||||
infoLog *log.Logger
|
||||
errorLog *log.Logger
|
||||
templateCache map[string]*template.Template
|
||||
version string
|
||||
@ -46,7 +47,7 @@ func (app *application) serve() error {
|
||||
WriteTimeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
app.infolog.Printf(
|
||||
app.infoLog.Printf(
|
||||
"Starting HTTP server in %s mode on port %d",
|
||||
app.config.env,
|
||||
app.config.port,
|
||||
@ -67,8 +68,8 @@ func main() {
|
||||
flag.StringVar(
|
||||
&cfg.db.dsn,
|
||||
"dsn",
|
||||
"root@tcp(localhost:6379)/widgets?parseTime=true&tls=false",
|
||||
"Application environment {development|production}",
|
||||
"root:example@tcp(localhost:3306)/widgets?parseTime=true&tls=false",
|
||||
"DSN",
|
||||
)
|
||||
flag.StringVar(&cfg.api, "api", "http://localhost:4001", "URL to api")
|
||||
|
||||
@ -80,17 +81,25 @@ func main() {
|
||||
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
|
||||
errorLog := log.New(os.Stdout, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
|
||||
conn, err := driver.OpenDB(cfg.db.dsn)
|
||||
if err != nil {
|
||||
errorLog.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
tc := make(map[string]*template.Template)
|
||||
|
||||
app := &application{
|
||||
config: cfg,
|
||||
infolog: infoLog,
|
||||
infoLog: infoLog,
|
||||
errorLog: errorLog,
|
||||
templateCache: tc,
|
||||
version: version,
|
||||
}
|
||||
|
||||
err := app.serve()
|
||||
app.infoLog.Println("Connected to MariaDB")
|
||||
|
||||
err = app.serve()
|
||||
if err != nil {
|
||||
app.errorLog.Println(err)
|
||||
log.Fatal(err)
|
||||
|
@ -57,12 +57,22 @@ Virtual Terminal
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input id="payment_intent" type="hidden" name="payment_intent" value="payment_intent">
|
||||
<input id="payment_method" type="hidden" name="payment_method" value="payment_method">
|
||||
<input id="payment_amount" type="hidden" name="payment_amount" value="payment_amount">
|
||||
<input id="payment_currency" type="hidden" name="payment_currency" value="payment_currency">
|
||||
|
||||
<input id="payment_intent"
|
||||
type="hidden"
|
||||
name="payment_intent"
|
||||
value="payment_intent">
|
||||
<input id="payment_method"
|
||||
type="hidden"
|
||||
name="payment_method"
|
||||
value="payment_method">
|
||||
<input id="payment_amount"
|
||||
type="hidden"
|
||||
name="payment_amount"
|
||||
value="payment_amount">
|
||||
<input id="payment_currency"
|
||||
type="hidden"
|
||||
name="payment_currency"
|
||||
value="payment_currency">
|
||||
</form>
|
||||
{{ end }}
|
||||
{{ define "js" }}
|
||||
|
Reference in New Issue
Block a user