mirror of
https://github.com/rjNemo/go-wiki
synced 2026-06-12 13:36:38 +00:00
add changelog, connection to psql database
This commit is contained in:
parent
4f006256e3
commit
36a83524a5
6 changed files with 31 additions and 9 deletions
3
CHANGELOG.md
Normal file
3
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Version 0.1 (2020-03-16)
|
||||||
|
|
||||||
|
Initial release
|
||||||
11
README.md
11
README.md
|
|
@ -1,6 +1,6 @@
|
||||||
# Go-Wiki
|
# Go-Wiki
|
||||||
|
|
||||||
Wiki web application model built using `go`
|
Wiki web application model built using `Go`
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ These instructions will get you a copy of the project up and running on your loc
|
||||||
|
|
||||||
### Prerequisites
|
### 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
|
### Installing
|
||||||
|
|
||||||
|
|
@ -35,6 +35,7 @@ Add additional notes about how to deploy this on a live system
|
||||||
## Built With
|
## Built With
|
||||||
|
|
||||||
- [Go](https://golang.org/) - Build simple, reliable, and efficient software
|
- [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
|
## Contributing
|
||||||
|
|
||||||
|
|
@ -42,13 +43,13 @@ Please read [CONTRIBUTING.md](contributing.md) for details on our code of conduc
|
||||||
|
|
||||||
## Versioning
|
## 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
|
## 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
|
## License
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,23 @@ import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
"github.com/rjNemo/go-wiki/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
// Connect read the connection parameters to establish a connection to the
|
||||||
connStr := "user=nemausat dbname=godb sslmode=verify-full"
|
// database.
|
||||||
|
func Connect() {
|
||||||
|
connStr := settings.ConnStr
|
||||||
db, err := sql.Open("postgres", connStr)
|
db, err := sql.Open("postgres", connStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
err = db.Ping()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Database successfully connected!")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
var exJson string = "https://jsonplaceholder.typicode.com/todos/1"
|
var exJson string = "https://jsonplaceholder.typicode.com/todos/1"
|
||||||
|
|
||||||
func Main() {
|
func FetchMain() {
|
||||||
b := FetchApi(exJson)
|
b := FetchApi(exJson)
|
||||||
fmt.Println(b)
|
fmt.Println(b)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/rjNemo/go-wiki/controller"
|
"github.com/rjNemo/go-wiki/controller"
|
||||||
|
"github.com/rjNemo/go-wiki/data"
|
||||||
"github.com/rjNemo/go-wiki/settings"
|
"github.com/rjNemo/go-wiki/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -14,6 +15,7 @@ func main() {
|
||||||
|
|
||||||
func startServer(p string, r func()) {
|
func startServer(p string, r func()) {
|
||||||
log.Printf("Start Go-wiki server on http://localhost:%s", p)
|
log.Printf("Start Go-wiki server on http://localhost:%s", p)
|
||||||
|
data.Connect()
|
||||||
port := ":" + p
|
port := ":" + p
|
||||||
r()
|
r()
|
||||||
log.Fatal(http.ListenAndServe(port, nil))
|
log.Fatal(http.ListenAndServe(port, nil))
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,17 @@ var Port = params.port
|
||||||
// TmplDir exposes the address of the templates folder.
|
// TmplDir exposes the address of the templates folder.
|
||||||
var TmplDir string = params.tmplDir
|
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
|
// Params struct holds the application settings parameters
|
||||||
type Params struct {
|
type Params struct {
|
||||||
// port exposes the port where the application is served.
|
// port exposes the port where the application is served.
|
||||||
port string
|
port string
|
||||||
// tmplDir must be set to the address of the templates folder.
|
// tmplDir must be set to the address of the templates folder.
|
||||||
tmplDir string
|
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
|
// NewParams reads env file then initialize a new Params object
|
||||||
|
|
@ -34,8 +39,9 @@ func NewParams(f string) Params {
|
||||||
}
|
}
|
||||||
port := getEnvParam("PORT")
|
port := getEnvParam("PORT")
|
||||||
tmplDir := getEnvParam("TMPLDIR")
|
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 {
|
func getEnvParam(s string) string {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue