Skip to content

Instantly share code, notes, and snippets.

View ntakouris's full-sized avatar
🤖
Building robots

Theodoros Ntakouris ntakouris

🤖
Building robots
View GitHub Profile
func Protect(authKey []byte, opts ...Option) func(http.Handler) http.Handler {
 //...
}
@ntakouris
ntakouris / botfunc.go
Created August 5, 2017 18:50
Bottom Functions
// Set the Vary: Cookie header to protect clients from caching the response.
 w.Header().Add("Vary", "Cookie")
 
 //and
 // Clear the request context after the handler has completed.
 contextClear(r)
@ntakouris
ntakouris / cookiesetup.go
Created August 5, 2017 18:51
Secure Cookie Init
// Create an authenticated securecookie instance.
if cs.sc == nil {
 cs.sc = securecookie.New(authKey, nil)
 // Use JSON serialization (faster than one-off gob encoding)
 cs.sc.SetSerializer(securecookie.JSONEncoder{})
 // Set the MaxAge of the underlying securecookie.
 cs.sc.MaxAge(cs.opts.MaxAge)
}
stage('Pre Test'){
echo 'Pulling Dependencies'
sh 'go version'
sh 'go get -u github.com/golang/dep/cmd/dep'
sh 'go get -u github.com/golang/lint/golint'
sh 'go get github.com/tebeka/go2xunit'
sh 'cd $GOPATH/src/cmd/project && dep ensure'
}
stage('Test'){
echo 'Testing, Linting, Vetting, Race Condition Detection'
sh 'go tool vet $GOPATH/src'
sh 'golint $GOPATH/src'
sh 'go test -race -cover'
}
def notifyBuild(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} ${env.BUILD_URL}"
node {
try{
notifyBuild('STARTED')
bitbucketStatusNotify(buildState: 'INPROGRESS')
//..work work..
}catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = "FAILED"
stage('Test'){
echo 'Testing, Linting, Vetting, Race Condition Detection'
//List all our project files with 'go list ./... | grep -v /vendor/ | grep -v github.com | grep -v golang.com'
sh 'go tool vet $(go list ./... | grep -v /vendor/ | grep -v github.com | grep -v golang.com)'
sh 'golint $(go list ./... | grep -v /vendor/ | grep -v github.com | grep -v golang.com)'
sh 'go test $(go list ./... | grep -v /vendor/ | grep -v github.com | grep -v golang.com) -race -cover'
}
node {
try{
notifyBuild('STARTED')
bitbucketStatusNotify(buildState: 'INPROGRESS')
ws("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/") {
withEnv(["GOPATH=${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}"]) {
env.PATH="${GOPATH}/bin:$PATH"
stage('Checkout'){
stage('Test'){
//List all our project files with 'go list ./... | grep -v /vendor/ | grep -v github.com | grep -v golang.org'
//Push our project files relative to ./src
sh 'cd $GOPATH && go list ./... | grep -v /vendor/ | grep -v github.com | grep -v golang.org > projectPaths'
//Print them with 'awk '$0="./src/"$0' projectPaths' in order to get full relative path to $GOPATH
def paths = sh returnStdout: true, script: """awk '\$0="./src/"\$0' projectPaths"""
echo 'Vetting'