Code Monkey home page Code Monkey logo

Comments (5)

mikeflynn avatar mikeflynn commented on July 25, 2024

Solid idea! I've pushed a branch called issue-5 (2de33f6) that breaks out the Run() function in to Run() and Init() with Init() allows you to add the application routes to a router you pass in to the function. It still requires a gorilla/mux router (*mux.Router) but this simple example I worked up works...

package main

import (
    "github.com/gorilla/mux"
    "net/http"

    alexa "github.com/mikeflynn/go-alexa/skillserver"
)

func YourHandler(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Gorilla!\n"))
}

func EchoIntentHandler(echoReq *alexa.EchoRequest, echoResp *alexa.EchoResponse) {
    echoResp.OutputSpeech("Hello world from my new Echo test app!").Card("Hello World", "This is a test card.")
}

func main() {
    var Applications = map[string]interface{}{
        "/echo/helloworld": alexa.EchoApplication{ // Route
            AppID:    "xxxxxxxx", // Echo App ID from Amazon Dashboard
            OnIntent: EchoIntentHandler,
            OnLaunch: EchoIntentHandler,
        },
    }

    r := mux.NewRouter()
    r.HandleFunc("/", YourHandler)

    alexa.Init(Applications, r)

    http.ListenAndServe(":8100", r)
}

Take a look at the branch when you get a chance and let me know if that works for you.

from go-alexa.

danverbraganza avatar danverbraganza commented on July 25, 2024

Cool, hopefully I'll get a chance to try it out next week. The way I hacked around it was to run the go-alexa server in a goroutine, and using net/http/util's NewSingleHostReverseProxy

from go-alexa.

mikeflynn avatar mikeflynn commented on July 25, 2024

I'm going to go ahead and merge this change in to master since it doesn't change how the primary use case works. Let me know if there's more to do here when you get a chance to play with it.

from go-alexa.

danverbraganza avatar danverbraganza commented on July 25, 2024

Awesome, just had a chance to check it, and it works perfectly.

It's a great change from the workaround I hacked together where I was using httputil.NewSingleHostReverseProxy() to proxy to the alexa server running in a different goroutine.

from go-alexa.

mikeflynn avatar mikeflynn commented on July 25, 2024

Good to hear! I love that hack but glad this simple change made things easier for you.

from go-alexa.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.