Skip to content

Commit

Permalink
added lint and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Aug 31, 2018
1 parent 4763b75 commit 1abdcee
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 47 deletions.
56 changes: 45 additions & 11 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

[[constraint]]
name = "github.com/lightningnetwork/lnd"
version = "0.4.1-beta"
version = "0.5.0-beta"

[[constraint]]
name = "github.com/op/go-logging"
Expand Down
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
# TODO: lint and fmt sub packages
PKG := github.com/michael1011/lightningtip

GOBUILD := go build -v
GOINSTALL := go install -v

GO_BIN := ${GOPATH}/bin
DEP_BIN := $(GO_BIN)/dep
LINT_BIN := $(GO_BIN)/gometalinter.v2

HAVE_DEP := $(shell command -v $(DEP_BIN) 2> /dev/null)

GOLIST := go list $(PKG)/... | grep -v '/vendor/'

GREEN := "\\033[0;32m"
NC := "\\033[0m"

define print
echo $(GREEN)$1$(NC)
endef

LINT = $(LINT_BIN) \
--disable-all \
--enable=gofmt \
--enable=vet \
--enable=golint \
--line-length=72 \
--deadline=4m $(GOLISTLINT) 2>&1 | \
grep -v 'ALL_CAPS\|OP_' 2>&1 | \
tee /dev/stderr

default: scratch

# Dependencies
Expand All @@ -39,4 +53,15 @@ install:
$(GOINSTALL) $(PKG)
$(GOINSTALL) $(PKG)/cmd/tipreport

scratch: dep build
scratch: dep build

# Utils

fmt:
@$(call print, "Formatting source.")
$(GOLIST) | go fmt -x

lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT_BIN) --install 1> /dev/null
test -z "$$($(LINT))"
18 changes: 8 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ const (
defaultRecipient = ""
defaultSender = ""

defaultSmtpServer = ""

defaultSmtpSSL = false
defaultSmtpUser = ""
defaultSmtpPassword = ""
defaultSTMPServer = ""
defaultSTMPSSL = false
defaultSTMPUser = ""
defaultSTMPPassword = ""
)

type config struct {
Expand Down Expand Up @@ -114,11 +113,10 @@ func initConfig() {
Recipient: defaultRecipient,
Sender: defaultSender,

SmtpServer: defaultSmtpServer,

SmtpSSL: defaultSmtpSSL,
SmtpUser: defaultSmtpUser,
SmtpPassword: defaultSmtpPassword,
SMTPServer: defaultSTMPServer,
SMTPSSL: defaultSTMPSSL,
SMTPUser: defaultSTMPUser,
SMTPPassword: defaultSTMPPassword,
},
}

Expand Down
48 changes: 24 additions & 24 deletions lightningtip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ package main
import (
"encoding/json"
"fmt"
"github.com/donovanhide/eventsource"
"github.com/michael1011/lightningtip/database"
"io/ioutil"
"net/http"
"os"
"strconv"
"strings"
"time"
)

const eventChannel = "invoiceSettled"

const couldNotParseError = "Could not parse values from request"

var eventSrv *eventsource.Server

var pendingInvoices []PendingInvoice
"github.com/donovanhide/eventsource"
"github.com/michael1011/lightningtip/database"
)

// PendingInvoice is for keeping alist of unpaid invoices
type PendingInvoice struct {
Invoice string
Amount int64
Expand All @@ -29,6 +23,14 @@ type PendingInvoice struct {
Expiry time.Time
}

const eventChannel = "invoiceSettled"

const couldNotParseError = "Could not parse values from request"

var eventSrv *eventsource.Server

var pendingInvoices []PendingInvoice

// To use the pendingInvoice type as event for the EventSource stream
func (pending PendingInvoice) Id() string { return "" }
func (pending PendingInvoice) Event() string { return "" }
Expand All @@ -41,7 +43,7 @@ type invoiceRequest struct {

type invoiceResponse struct {
Invoice string
RHash string
RHash string
Expiry int64
}

Expand Down Expand Up @@ -282,7 +284,7 @@ func invoiceSettledHandler(writer http.ResponseWriter, request *http.Request) {

}

writer.Write(marshalJson(invoiceSettledResponse{
writer.Write(marshalJSON(invoiceSettledResponse{
Settled: settled,
}))

Expand Down Expand Up @@ -335,23 +337,21 @@ func getInvoiceHandler(writer http.ResponseWriter, request *http.Request) {
Expiry: time.Now().Add(expiryDuration),
})

writer.Write(marshalJson(invoiceResponse{
writer.Write(marshalJSON(invoiceResponse{
Invoice: invoice,
RHash: paymentHash,
RHash: paymentHash,
Expiry: cfg.TipExpiry,
}))

return
}

} else {
errorMessage = "Failed to create invoice"

// This is way too hacky
// Maybe a cast to the gRPC error and get its error message directly
if fmt.Sprint(err)[:47] == "rpc error: code = Unknown desc = memo too large" {
errorMessage += ": message too long"
}
errorMessage = "Failed to create invoice"

// This is way too hacky
// Maybe a cast to the gRPC error and get its error message directly
if fmt.Sprint(err)[:47] == "rpc error: code = Unknown desc = memo too large" {
errorMessage += ": message too long"
}

}
Expand Down Expand Up @@ -387,12 +387,12 @@ func handleHeaders(handler func(w http.ResponseWriter, r *http.Request)) http.Ha
func writeError(writer http.ResponseWriter, message string) {
writer.WriteHeader(http.StatusBadRequest)

writer.Write(marshalJson(errorResponse{
writer.Write(marshalJSON(errorResponse{
Error: message,
}))
}

func marshalJson(data interface{}) []byte {
func marshalJSON(data interface{}) []byte {
response, _ := json.MarshalIndent(data, "", " ")

return response
Expand Down

0 comments on commit 1abdcee

Please sign in to comment.