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