gofmt, delete works
This commit is contained in:
parent
8f9969b4cc
commit
bc7fcdde54
|
@ -2,10 +2,10 @@ package categories
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
_ "github.com/lib/pq"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
|
@ -86,7 +86,6 @@ func Delete(db *sql.DB, id int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_, err = db.Exec("UPDATE news SET category_id =$2 WHERE category_id=$1", id, parent_id)
|
_, err = db.Exec("UPDATE news SET category_id =$2 WHERE category_id=$1", id, parent_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Categories DB error changing category of news: ", err)
|
fmt.Println("Categories DB error changing category of news: ", err)
|
||||||
|
|
3
main.go
3
main.go
|
@ -3,12 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"flag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -73,7 +73,6 @@ func main() {
|
||||||
envFlag := flag.String("env", "local", "load config/{env}.json")
|
envFlag := flag.String("env", "local", "load config/{env}.json")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
|
||||||
fmt.Println("Loading...")
|
fmt.Println("Loading...")
|
||||||
|
|
||||||
loadConfig(*envFlag)
|
loadConfig(*envFlag)
|
||||||
|
|
13
news/news.go
13
news/news.go
|
@ -1,12 +1,11 @@
|
||||||
package news
|
package news
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
_ "github.com/lib/pq"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dballard/transmet/categories"
|
"github.com/dballard/transmet/categories"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type News struct {
|
type News struct {
|
||||||
|
@ -34,7 +33,7 @@ type NewsContainer struct {
|
||||||
|
|
||||||
// Insert News item into DB
|
// Insert News item into DB
|
||||||
func (news *News) Insert(db *sql.DB) error {
|
func (news *News) Insert(db *sql.DB) error {
|
||||||
_, err := db.Exec("INSERT INTO news (url, title, category_id, notes) VALUES($1, $2, $3, $4)", news.Url, news.Title, news.Category_id, news.Notes );
|
_, err := db.Exec("INSERT INTO news (url, title, category_id, notes) VALUES($1, $2, $3, $4)", news.Url, news.Title, news.Category_id, news.Notes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error inserting news: ", err)
|
fmt.Println("Error inserting news: ", err)
|
||||||
return err
|
return err
|
||||||
|
@ -43,6 +42,11 @@ func (news *News) Insert(db *sql.DB) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(db *sql.DB, id int) error {
|
func Delete(db *sql.DB, id int) error {
|
||||||
|
_, err := db.Exec("DELETE FROM news WHERE id = $1", id)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error deleting news: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -121,7 +125,6 @@ func convertSqlToNews(rows *sql.Rows) ([]*News, int, error) {
|
||||||
continue // needs a category id
|
continue // needs a category id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
news = append(news, newsItem)
|
news = append(news, newsItem)
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/mux"
|
"bytes"
|
||||||
"github.com/gorilla/sessions"
|
|
||||||
"net/http"
|
|
||||||
"github.com/dballard/transmet/user"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"io/ioutil"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"strconv"
|
|
||||||
"github.com/dballard/transmet/categories"
|
"github.com/dballard/transmet/categories"
|
||||||
"github.com/dballard/transmet/news"
|
"github.com/dballard/transmet/news"
|
||||||
"bytes"
|
"github.com/dballard/transmet/user"
|
||||||
txtTemplate "text/template"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/gorilla/sessions"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
txtTemplate "text/template"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
||||||
|
@ -254,7 +254,6 @@ func deleteHandler(w http.ResponseWriter, r *http.Request, user *user.User, sess
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func categoriesFormHandler(w http.ResponseWriter, r *http.Request, user *user.User, session *sessions.Session) {
|
func categoriesFormHandler(w http.ResponseWriter, r *http.Request, user *user.User, session *sessions.Session) {
|
||||||
flashes := GetFlashes(session)
|
flashes := GetFlashes(session)
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/dballard/transmet/categories"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"net/http"
|
|
||||||
"errors"
|
|
||||||
"time"
|
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/dballard/transmet/categories"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -75,7 +75,6 @@ var funcMap = template.FuncMap {
|
||||||
"truncate": truncate,
|
"truncate": truncate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func initTemplates() {
|
func initTemplates() {
|
||||||
files, _ := filepath.Glob("templates/pages/*.html")
|
files, _ := filepath.Glob("templates/pages/*.html")
|
||||||
re := regexp.MustCompile("templates/pages/(.*).html")
|
re := regexp.MustCompile("templates/pages/(.*).html")
|
||||||
|
|
Loading…
Reference in New Issue