github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/examples/go_extension/exampleapp.go (about)

     1  // Copyright (C) 2015 NTT Innovation Institute, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package main
    17  
    18  import (
    19  	"fmt"
    20  
    21  	"github.com/cloudwan/gohan/cli"
    22  	"github.com/cloudwan/gohan/extension/golang"
    23  	"github.com/cloudwan/gohan/extension/otto"
    24  )
    25  
    26  //ExampleModule shows example javascript module
    27  type ExampleModule struct {
    28  }
    29  
    30  //HelloWorld shows example function
    31  func (example *ExampleModule) HelloWorld(name string, profile map[string]interface{}) {
    32  	fmt.Printf("Hello %s %v\n", name, profile)
    33  }
    34  
    35  func main() {
    36  	//Customize code
    37  
    38  	//Register go callback
    39  	golang.RegisterGoCallback("exampleapp_callback",
    40  		func(event string, context map[string]interface{}) error {
    41  			fmt.Printf("callback on %s : %v", event, context)
    42  			return nil
    43  		})
    44  
    45  	exampleModule := &ExampleModule{}
    46  
    47  	//Register go based module for javascript
    48  	otto.RegisterModule("exampleapp", exampleModule)
    49  	cli.Run("exampleapp", "exampleapp", "0.0.1")
    50  }