New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add google go template #5726

Merged
merged 5 commits into from Jan 22, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to鈥
Jump to file or symbol
Failed to load files and symbols.
+152 鈭0
Diff settings

Always

Just for now

Copy path View file
@@ -102,6 +102,11 @@ services:
image: node:6.9.1 image: node:6.9.1
volumes: volumes:
- ./tmp/serverless-integration-test-google-nodejs:/app - ./tmp/serverless-integration-test-google-nodejs:/app
google-go:
image: golang:1.11
volumes:
- ./tmp/serverless-integration-test-google-go:/app
This conversation was marked as resolved by pmuens

This comment has been minimized.

@sebito91

sebito91 Jan 21, 2019

Member

Should also need the $GOPATH location as well, look at aws-go:

  google-go:
    image: golang:1.11
    volumes:
      - ./tmp/serverless-integration-test-google-go:/app
      - ./tmp/serverless-integration-test-google-go:/go/src/app
- ./tmp/serverless-integration-test-google-go:/go/src/app
spotinst-nodejs: spotinst-nodejs:
image: node:4.8 image: node:4.8
volumes: volumes:
@@ -41,6 +41,7 @@ To see a list of available templates run `serverless create --help`
Most commonly used templates: Most commonly used templates:


- google-nodejs - google-nodejs
- google-go


## Examples ## Examples


Copy path View file
@@ -42,6 +42,7 @@ const validTemplates = [
'fn-nodejs', 'fn-nodejs',
'fn-go', 'fn-go',
'google-nodejs', 'google-nodejs',
'google-go',
'kubeless-python', 'kubeless-python',
'kubeless-nodejs', 'kubeless-nodejs',
'openwhisk-java-maven', 'openwhisk-java-maven',
@@ -567,6 +567,20 @@ describe('Create', () => {
}); });
}); });


it('should generate scaffolding for "google-go" template', () => {
process.chdir(tmpDir);
create.options.template = 'google-go';

return create.create().then(() => {
const dirContent = fs.readdirSync(tmpDir);
expect(dirContent).to.include('fn.go');
expect(dirContent).to.include('fn_test.go');
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('Makefile');
expect(dirContent).to.include('.gitignore');
});
});

it('should generate scaffolding for "kubeless-python" template', () => { it('should generate scaffolding for "kubeless-python" template', () => {
process.chdir(tmpDir); process.chdir(tmpDir);
create.options.template = 'kubeless-python'; create.options.template = 'kubeless-python';
@@ -0,0 +1,12 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
@@ -0,0 +1,10 @@
.PHONY: gomodgen deploy delete

gomodgen:
GO111MODULE=on go mod init

deploy:
gcloud functions deploy hello --entry-point Hello --runtime go111 --trigger-http

delete:
gcloud functions delete hello --entry-point Hello --runtime go111 --trigger-http
@@ -0,0 +1,14 @@
package hello

import (
"fmt"
"net/http"
)

func Hello(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
if name == "" {
name = "someone"
}
fmt.Fprintf(w, "Hello, %s!", name)
}
@@ -0,0 +1,44 @@
package hello

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)

func TestHello(t *testing.T) {
tests := map[string]struct {
name string
wantStatus int
wantString string
}{
"name specified": {"jdoe", http.StatusOK, "Hello, jdoe!"},
"name not specified": {"", http.StatusOK, "Hello, someone!"},
}

for name, te := range tests {
t.Run(name, func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)
q := r.URL.Query()
q.Add("name", te.name)
r.URL.RawQuery = q.Encode()

Hello(w, r)

rw := w.Result()
defer rw.Body.Close()
if s := rw.StatusCode; s != te.wantStatus {
t.Fatalf("got: %d, want: %d", s, te.wantStatus)
}
b, err := ioutil.ReadAll(rw.Body)
if err != nil {
t.Fatal("failed to read res body")
}
if s := string(b); s != te.wantString {
t.Fatalf("got: %s, want: %s", s, te.wantString)
}
})
}
}
@@ -0,0 +1,47 @@
service: gcf-go111 # NOTE: Don't put the word "google" in here

provider:
name: google
runtime: go111
project: my-project
# The GCF credentials can be a little tricky to set up. Luckily we've documented this for you here:
# https://serverless.com/framework/docs/providers/google/guide/credentials/
#
# the path to the credentials file needs to be absolute
This conversation was marked as resolved by pmuens

This comment has been minimized.

@sebito91

sebito91 Jan 21, 2019

Member

Would add a reference to the docs as we have in the examples repo:


# The GCF credentials can be a little tricky to set up. Luckily we've documented this for you here:
# https://serverless.com/framework/docs/providers/google/guide/credentials/
# 
# the path to the credentials file needs to be absolute

This comment has been minimized.

@toshi0607

toshi0607 Jan 21, 2019

Author Contributor

Great docs! I also added to the node one.

credentials: ~/.gcloud/keyfile.json

plugins:
- serverless-google-cloudfunctions

# needs more granular excluding in production as only the serverless provider npm
# package should be excluded (and not the whole node_modules directory)
package:
exclude:
- .gitignore
- .git/**

functions:
first:
handler: http
events:
- http: path

# NOTE: the following uses an "event" event (pubSub event in this case).
# Please create the corresponding resources in the Google Cloud
# before deploying this service through Serverless

#second:
# handler: event
# events:
# - event:
# eventType: providers/cloud.pubsub/eventTypes/topic.publish
# resource: projects/*/topics/my-topic

# you can define resources, templates etc. the same way you would in a
# Google Cloud deployment configuration
#resources:
# resources:
# - type: storage.v1.bucket
# name: my-serverless-service-bucket
# imports:
# - path: my_template.jinja
@@ -4,6 +4,9 @@ provider:
name: google name: google
runtime: nodejs runtime: nodejs
project: my-project project: my-project
# The GCF credentials can be a little tricky to set up. Luckily we've documented this for you here:
# https://serverless.com/framework/docs/providers/google/guide/credentials/
#
# the path to the credentials file needs to be absolute # the path to the credentials file needs to be absolute
credentials: ~/.gcloud/keyfile.json credentials: ~/.gcloud/keyfile.json


@@ -30,6 +30,7 @@ integration-test aws-nodejs-typescript
integration-test aws-alexa-typescript integration-test aws-alexa-typescript
integration-test aws-nodejs-ecma-script integration-test aws-nodejs-ecma-script
integration-test google-nodejs integration-test google-nodejs
integration-test google-go
integration-test spotinst-nodejs integration-test spotinst-nodejs
integration-test spotinst-python integration-test spotinst-python
integration-test spotinst-ruby integration-test spotinst-ruby
ProTip! Use n and p to navigate between commits in a pull request.