Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
ccojocar committed Jul 23, 2018
0 parents commit a109e5a
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
Makefile linguist-vendored
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
.project
.classpath
.idea
.cache
.DS_Store
*.im?
target
work
bin/
68 changes: 68 additions & 0 deletions Makefile
@@ -0,0 +1,68 @@
SHELL := /bin/bash
GO := GO15VENDOREXPERIMENT=1 go
NAME := REPLACE_ME_APP_NAME
OS := $(shell uname)
MAIN_GO := main.go
ROOT_PACKAGE := $(GIT_PROVIDER)/$(ORG)/$(NAME)
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/)
PKGS := $(shell go list ./... | grep -v /vendor | grep -v generated)
PKGS := $(subst :,_,$(PKGS))
BUILDFLAGS := ''
CGO_ENABLED = 0
VENDOR_DIR=vendor

all: build

check: fmt build test

build:
CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO)

test:
CGO_ENABLED=$(CGO_ENABLED) $(GO) test $(PACKAGE_DIRS) -test.v

full: $(PKGS)

install:
GOBIN=${GOPATH}/bin $(GO) install -ldflags $(BUILDFLAGS) $(MAIN_GO)

fmt:
@FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)`
@([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true

clean:
rm -rf build release

linux:
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO)

.PHONY: release clean

FGT := $(GOPATH)/bin/fgt
$(FGT):
go get github.com/GeertJohan/fgt

GOLINT := $(GOPATH)/bin/golint
$(GOLINT):
go get github.com/golang/lint/golint

$(PKGS): $(GOLINT) $(FGT)
@echo "LINTING"
@$(FGT) $(GOLINT) $(GOPATH)/src/$@/*.go
@echo "VETTING"
@go vet -v $@
@echo "TESTING"
@go test -v $@

.PHONY: lint
lint: vendor | $(PKGS) $(GOLINT) #
@cd $(BASE) && ret=0 && for pkg in $(PKGS); do \
test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \
done ; exit $$ret

watch:
reflex -r "\.go$" -R "vendor.*" make skaffold-run

skaffold-run: build
skaffold run -p dev
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
# golang-http
10 changes: 10 additions & 0 deletions curlloop.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

export APP="$1"
echo "curling URL $APP in a loop..."

while true
do
curl $APP
sleep 2
done
26 changes: 26 additions & 0 deletions main.go
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"log"
"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
title := "Jenkins X golang http example"

from := ""
if r.URL != nil {
from = r.URL.String()
}
if from != "/favicon.ico" {
log.Printf("title: %s\n", title)
}

fmt.Fprintf(w, "Hello from: "+title+"\n")
}

func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
4 changes: 4 additions & 0 deletions watch.sh
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

make skaffold-run
reflex -r "\.go$" -R "vendor.*" make skaffold-run

0 comments on commit a109e5a

Please sign in to comment.