diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6b6a050 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Version 0.1 (2020-03-16) + +Initial release diff --git a/README.md b/README.md index 598a1d6..0baaf26 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Go-Wiki -Wiki web application model built using `go` +Wiki web application model built using `Go` ## Getting Started @@ -8,7 +8,7 @@ These instructions will get you a copy of the project up and running on your loc ### Prerequisites -You need Go v1.14+ to install `Go-Wiki`. [Get official installation](https://golang.org/doc/install) +You need `Go v1.14+` to install `Go-Wiki`. [Get official installation](https://golang.org/doc/install) ### Installing @@ -35,6 +35,7 @@ Add additional notes about how to deploy this on a live system ## Built With - [Go](https://golang.org/) - Build simple, reliable, and efficient software +- [Bootstrap](https://getbootstrap.com/) - The most popular HTML, CSS, and JS library in the world ## Contributing @@ -42,13 +43,13 @@ Please read [CONTRIBUTING.md](contributing.md) for details on our code of conduc ## Versioning -We use [SemVer](https://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/rjNemo/go-wiki/tags). +We use [SemVer](https://semver.org/) for versioning. For the versions available, see the [CHANGELOG.md](CHANGELOG.md) and the [tags on this repository](https://github.com/rjNemo/go-wiki/tags). ## Authors -- **Ruidy Nemausat** - _Initial work_ - [PurpleBooth](https://github.com/rjNemo) +- **Ruidy Nemausat** - _Initial work_ - [rjNemo](https://github.com/rjNemo) -See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project. +See also the list of [contributors](https://github.com/rjNemo/go-wiki/contributors) who participated in this project. ## License diff --git a/data/database.go b/data/database.go index 27bc4ef..9f0d322 100644 --- a/data/database.go +++ b/data/database.go @@ -5,13 +5,23 @@ import ( "log" _ "github.com/lib/pq" + "github.com/rjNemo/go-wiki/settings" ) -func main() { - connStr := "user=nemausat dbname=godb sslmode=verify-full" +// Connect read the connection parameters to establish a connection to the +// database. +func Connect() { + connStr := settings.ConnStr db, err := sql.Open("postgres", connStr) if err != nil { log.Fatal(err) } defer db.Close() + + err = db.Ping() + if err != nil { + log.Fatal(err) + } + + log.Println("Database successfully connected!") } diff --git a/data/fetch.go b/data/fetch.go index 476ef5f..9b3cb27 100644 --- a/data/fetch.go +++ b/data/fetch.go @@ -11,7 +11,7 @@ import ( var exJson string = "https://jsonplaceholder.typicode.com/todos/1" -func Main() { +func FetchMain() { b := FetchApi(exJson) fmt.Println(b) } diff --git a/main.go b/main.go index 1ffe409..15bb6ac 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/rjNemo/go-wiki/controller" + "github.com/rjNemo/go-wiki/data" "github.com/rjNemo/go-wiki/settings" ) @@ -14,6 +15,7 @@ func main() { func startServer(p string, r func()) { log.Printf("Start Go-wiki server on http://localhost:%s", p) + data.Connect() port := ":" + p r() log.Fatal(http.ListenAndServe(port, nil)) diff --git a/settings/settings.go b/settings/settings.go index f0b004b..3dbde6e 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -18,12 +18,17 @@ var Port = params.port // TmplDir exposes the address of the templates folder. var TmplDir string = params.tmplDir +// ConnStr exposes the connection string to the database. +var ConnStr string = params.connStr + // Params struct holds the application settings parameters type Params struct { // port exposes the port where the application is served. port string // tmplDir must be set to the address of the templates folder. tmplDir string + // connStr must be set to the connection string to the database. + connStr string } // NewParams reads env file then initialize a new Params object @@ -34,8 +39,9 @@ func NewParams(f string) Params { } port := getEnvParam("PORT") tmplDir := getEnvParam("TMPLDIR") + connStr := getEnvParam("ConnectionString") - return Params{port: port, tmplDir: tmplDir} + return Params{port: port, tmplDir: tmplDir, connStr: connStr} } func getEnvParam(s string) string {