Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Document SDK #31

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions async.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

// Async is an asynchronous Event interface
type Async interface {
Event
GetType() string
Expand Down
17 changes: 17 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

// Context is event context
type Context struct {
Logger Logger
DataBinding map[string]DataBinding
Expand Down
17 changes: 17 additions & 0 deletions databinding.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

// DataBinding is event data binding
type DataBinding interface {
// TODO
}
16 changes: 16 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

/*
Expand Down
2 changes: 2 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: This will be documented once https://github.com/nuclio/nuclio-sdk/pull/21 is merged

package nuclio

type WithStatusCode interface {
Expand Down
125 changes: 21 additions & 104 deletions event.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

import (
"errors"
"time"
)

// ErrUnsupported means Event does not support a method
var ErrUnsupported = errors.New("Event does not support this interface")

// SourceInfoProvider is event source provider
type SourceInfoProvider interface {

// get the class of source (sync, async, etc)
// GetClass gets the class of source (sync, async, etc)
GetClass() string

// get specific kind of source (http, rabbit mq, etc)
// GetKind gets specific kind of source (http, rabbit mq, etc)
GetKind() string
}

//
// An event
//

// Event is a nuclio event
type Event interface {
GetVersion() int
GetID() ID
Expand All @@ -43,99 +56,3 @@ type Event interface {
GetURL() string
GetMethod() string
}

//
// Abstract implementation of event
//

type AbstractEvent struct {
sourceInfoProvider SourceInfoProvider
id ID
emptyByteArray []byte
emptyHeaders map[string]interface{}
emptyTime time.Time
}

func (ae *AbstractEvent) GetVersion() int {
return 0
}

func (ae *AbstractEvent) SetSourceProvider(sourceInfoProvider SourceInfoProvider) {
ae.sourceInfoProvider = sourceInfoProvider
}

func (ae *AbstractEvent) GetSource() SourceInfoProvider {
return ae.sourceInfoProvider
}

func (ae *AbstractEvent) GetID() ID {
return ae.id
}

func (ae *AbstractEvent) SetID(id ID) {
ae.id = id
}

func (ae *AbstractEvent) GetContentType() string {
return ""
}

func (ae *AbstractEvent) GetBody() []byte {
return ae.emptyByteArray
}

func (ae *AbstractEvent) GetSize() int {
return 0
}

func (ae *AbstractEvent) GetHeader(key string) interface{} {
return nil
}

func (ae *AbstractEvent) GetHeaderByteSlice(key string) []byte {
return ae.emptyByteArray
}

func (ae *AbstractEvent) GetHeaderString(key string) string {
return string(ae.GetHeaderByteSlice(key))
}

func (ae *AbstractEvent) GetHeaders() map[string]interface{} {
return ae.emptyHeaders
}

func (ae *AbstractEvent) GetTimestamp() time.Time {
return ae.emptyTime
}

func (ae *AbstractEvent) GetPath() string {
return ""
}

func (ae *AbstractEvent) GetURL() string {
return ""
}

func (ae *AbstractEvent) GetMethod() string {
return ""
}

func (ae *AbstractEvent) GetField(key string) interface{} {
return nil
}

func (ae *AbstractEvent) GetFieldByteSlice(key string) []byte {
return nil
}

func (ae *AbstractEvent) GetFieldString(key string) string {
return ""
}

func (ae *AbstractEvent) GetFieldInt(key string) (int, error) {
return 0, ErrUnsupported
}

func (ae *AbstractEvent) GetFields() map[string]interface{} {
return nil
}
2 changes: 1 addition & 1 deletion examples/event-sources/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func GolangExample(context *nuclio.Context, event nuclio.Event) (interface{}, er
return nuclio.Response{
StatusCode: 201,
ContentType: "application/text",
Headers: map[string]string{
Headers: map[string]interface{}{
"x-v3io-something": "30",
},
Body: []byte("Response from golang"),
Expand Down
21 changes: 19 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

// Logger is logging interface
type Logger interface {

// emit a log entry of a given verbosity. the first argument may be an object, a string
Expand All @@ -21,9 +38,9 @@ type Logger interface {
InfoWith(format interface{}, vars ...interface{})
DebugWith(format interface{}, vars ...interface{})

// flushes buffered logs, if applicable
// Flush flushes buffered logs, if applicable
Flush()

// returns a child logger, if underlying logger supports hierarchal logging
// GetChild returns a child logger, if underlying logger supports hierarchal logging
GetChild(name string) interface{}
}
17 changes: 17 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

// Response is a response object
type Response struct {
StatusCode int
ContentType string
Expand Down
37 changes: 17 additions & 20 deletions sync.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

// Sync is synchronous event
type Sync interface {
Event
GetHostAddress() string
GetRemoteAddress() string
GetWorkflowStep() string
GetQuery() map[string]interface{}
}

type AbstractSync struct {
AbstractEvent
}

func (as *AbstractSync) GetHostAddress() string {
return ""
}

func (as *AbstractSync) GetRemoteAddress() string {
return ""
}

func (as *AbstractSync) GetWorkflowStep() string {
return ""
}

func (as *AbstractSync) GetQuery() map[string]interface{} {
return map[string]interface{}{}
}
16 changes: 16 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2017 The Nuclio Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package nuclio

import (
Expand Down