refactor-code-modules #1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
logs/
|
logs/
|
||||||
badgerdb/
|
badgerdb/
|
||||||
|
notes.md
|
||||||
|
@ -15,10 +15,6 @@ const (
|
|||||||
CollectionName = "shares"
|
CollectionName = "shares"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handlers struct {
|
|
||||||
DB *clover.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitDatabase() (*clover.DB, error) {
|
func InitDatabase() (*clover.DB, error) {
|
||||||
store, err := badgerstore.Open("badgerdb")
|
store, err := badgerstore.Open("badgerdb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
4
main.go
4
main.go
@ -20,12 +20,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
database.PrintAllHashes(db)
|
|
||||||
|
|
||||||
go ingest.WatchAndIngest(db)
|
go ingest.WatchAndIngest(db)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
handlers := database.Handlers{DB: db}
|
handlers := web.Handlers{DB: db}
|
||||||
http.HandleFunc("/", handlers.IndexHandler)
|
http.HandleFunc("/", handlers.IndexHandler)
|
||||||
fmt.Println("Listening on :8081")
|
fmt.Println("Listening on :8081")
|
||||||
log.Fatal(http.ListenAndServe(":8081", nil))
|
log.Fatal(http.ListenAndServe(":8081", nil))
|
||||||
|
@ -4,11 +4,16 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"pool-stats/database"
|
|
||||||
"pool-stats/stats"
|
"pool-stats/stats"
|
||||||
|
|
||||||
|
"github.com/ostafen/clover/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h database.Handlers) IndexHandler(w http.ResponseWriter, r *http.Request) {
|
type Handlers struct {
|
||||||
|
DB *clover.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h Handlers) IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
shareStats, err := stats.GetStats(h.DB)
|
shareStats, err := stats.GetStats(h.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to load stats", 500)
|
http.Error(w, "Failed to load stats", 500)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user