Пример #1
0
// New() returns a blank Websocket Controller
func New() *Controller {
	this := new(Controller)
	this.onOpen = rack.New()
	this.onMessage = rack.New()
	this.onClose = rack.New()
	this.ReceiveTextMessages()
	return this
}
Пример #2
0
func (this FakeProvider) Middleware() rack.Middleware {
	if this.middleware == nil {
		hostcept := interceptor.New()
		hostcept.Intercept("/auth", rack.Func(func(vars map[string]interface{}, next func()) {
			values := url.Values{}
			values.Set("state", parser.V(vars).FormValue("state"))
			values.Set("code", "c0D3")
			redirecter.V(vars).Redirect(parser.V(vars).FormValue("redirect_uri") + "?" + values.Encode())
		}))
		hostcept.Intercept("/token", rack.Func(func(vars map[string]interface{}, next func()) {
			if parser.V(vars).FormValue("code") == "c0D3" {
				httper.V(vars).GetRequest().Header.Set("content-type", "application/json")
				httper.V(vars).SetMessageString("{\"access_token\":\"tokendata\",\"refresh_token\":\"refreshtoken1\",\"expires_in\":3600}")
			}
		}))
		hostcept.Intercept("/data", rack.Func(func(vars map[string]interface{}, next func()) {
			if auth := httper.V(vars).GetRequest().Header.Get("Authorization"); auth != "Bearer tokendata" {
				httper.V(vars).SetMessageString("Invalid authorization: " + auth)
			}
			httper.V(vars).SetMessageString("payload")
		}))
		hostrackup := rack.New()
		hostrackup.Add(sessioner.Middleware)
		hostrackup.Add(hostcept)

		this.middleware = hostrackup
	}
	return this.middleware
}
Пример #3
0
func init() {
	rackup := rack.New()
	rackup.Add(Form)
	rackup.Add(HttpWare)

	conn := httper.HttpConnection(":4007")
	go conn.Go(rackup)
}
Пример #4
0
func init() {
	rackup := rack.New()
	rackup.Add(parser.Form)
	rackup.Add(Override)
	rackup.Add(HttpWare)

	conn := httper.HttpConnection(":4005")
	go conn.Go(rackup)
}
Пример #5
0
func Example_NoLogger() {
	rackup := rack.New()
	rackup.Add(HelloWorldWare)

	conn := httper.HttpConnection(":4004")
	go conn.Go(rackup)
	http.Get("http://localhost:4004")
	//output:
}
Пример #6
0
func Example_Basic() {
	rackup := rack.New()
	rackup.Add(New(os.Stdout, "Log Test - ", 0))
	rackup.Add(HelloWorldWare)

	conn := httper.HttpConnection(":4003")
	go conn.Go(rackup)
	http.Get("http://localhost:4003")
	//output: Log Test - Hello World!
}
func Example_Basic() {
	rackup := rack.New()
	rackup.Add(logger.New(os.Stdout, "", 0))
	rackup.Add(Logger)

	conn := httper.HttpConnection(":4009")
	go conn.Go(rackup)
	http.Get("http://localhost:4009/location")
	//output: GET /location
}
Пример #8
0
func Example_Skipped() {
	rackup := rack.New()
	rackup.Add(HttpWare)

	conn := httper.HttpConnection(":3001")
	go conn.Go(rackup)

	PostTo("http://localhost:3001", url.Values{"Name": {"Jim"}})
	//output: Welcome, Jim
}
Пример #9
0
func Example_Basic() {
	rackup := rack.New()
	rackup.Add(New("/static/", "./test_files"))

	conn := httper.HttpConnection(":4013")
	go conn.Go(rackup)

	GetFrom("http://localhost:4013/static/test.txt")
	//output: Hello World!
}
Пример #10
0
func Example_Multipart() {
	rackup := rack.New()
	rackup.Add(Multipart{256})
	rackup.Add(FileWare)

	conn := httper.HttpConnection(":3002")
	go conn.Go(rackup)

	SendFileTo("http://localhost:3002", "./test_files/helloworld.txt")
	//output: Hello World
}
Пример #11
0
func init() {
	cept := New()
	cept.Intercept("/helloworld", HelloWorldWare)

	rackup := rack.New()
	rackup.Add(cept)
	rackup.Add(RootWare)

	conn := httper.HttpConnection(":4002")
	go conn.Go(rackup)
}
Пример #12
0
func Example_NoError() {
	rackup := rack.New()
	rackup.Add(ErrorHandler)
	rackup.Add(rack.Func(func(vars map[string]interface{}, next func()) {
		httper.V(vars).SetMessageString("Just Fine!")
	}))

	conn := httper.HttpConnection(":3002")
	go conn.Go(rackup)

	GetFrom("http://localhost:3002/")
	//output: Just Fine!
}
Пример #13
0
func Example_Specific() {
	rackup := rack.New()
	rackup.Add(templater.GetTemplates("test_templates"))
	rackup.Add(encapsulator.AddLayout)
	rackup.Add(SetErrorLayout)

	conn := httper.HttpConnection(":3001")
	go conn.Go(rackup)

	GetFrom("http://localhost:3001/")

	//output: Not Found
}
Пример #14
0
func Example_SpecificOverride() {
	rackup := rack.New()
	rackup.Add(templater.GetTemplates("test_templates"))
	rackup.Add(encapsulator.AddLayout)
	rackup.Add(SetErrorLayout)
	rackup.Add(ErrorWare2)

	conn := httper.HttpConnection(":3002")
	go conn.Go(rackup)

	GetFrom("http://localhost:3002/")

	//output: Not Implemented!
}
Пример #15
0
func Example_General() {
	rackup := rack.New()
	rackup.Add(templater.GetTemplates("test_templates"))
	rackup.Add(encapsulator.AddLayout)
	rackup.Add(SetErrorLayout)
	rackup.Add(ErrorWare)

	conn := httper.HttpConnection(":4014")
	go conn.Go(rackup)

	GetFrom("http://localhost:4014/")

	//output: Error - 500
}
Пример #16
0
func Example_Basic() {
	rackup := rack.New()
	rackup.Add(V{"world": "World!"})
	rackup.Add(rack.Func(func(vars map[string]interface{}, next func()) {
		world := vars["world"].(string)
		(httper.V)(vars).SetMessageString("Hello " + world)
	}))

	conn := httper.HttpConnection(":4015")
	go conn.Go(rackup)

	GetFrom("http://localhost:4015/")
	//output: Hello World!
}
Пример #17
0
func Example_Session() {
	rackup := rack.New()
	rackup.Add(Middleware)
	rackup.Add(HelloWorldWare)

	conn := httper.HttpConnection(":4012")
	go conn.Go(rackup)

	var cookies []*http.Cookie
	for i := 0; i < 4; i++ {
		cookies = GetWithCookies("http://localhost:4012", cookies)
	}
	//output: 1234
}
Пример #18
0
func Example_BasicError() {
	rackup := rack.New()
	rackup.Add(ErrorHandler)
	rackup.Add(rack.Func(func(vars map[string]interface{}, next func()) {
		httper.V(vars).SetMessageString("Just Fine!")
		array := make([]byte, 0)
		array[1] = 0 //this action results in a runtime error; we are indexing past the range of the slice
	}))

	conn := httper.HttpConnection(":4001")
	go conn.Go(rackup)

	GetFrom("http://localhost:4001/")
	//output: runtime error: index out of range
}
Пример #19
0
func Example_NoLayout() {
	rackup := rack.New()
	rackup.Add(templater.GetTemplates("./test_templates"))
	rackup.Add(AddLayout)
	rackup.Add(rack.Func(func(vars map[string]interface{}, next func()) {
		vars["Title"] = "Hello World"
		(httper.V)(vars).AppendMessageString("Hello World!")
	}))

	conn := httper.HttpConnection(":3001")
	go conn.Go(rackup)

	GetFrom("http://localhost:3001/")
	//output: Hello World!
}
Пример #20
0
func Example_Render() {
	rackup := rack.New()
	rackup.Add(logger.New(os.Stdout, "", 0))
	rackup.Add(templater.GetTemplates("./test_templates"))
	rackup.Add(rack.Func(func(vars map[string]interface{}, next func()) {
		vars["Object"] = "World"
		next()
	}))
	rackup.Add(Renderer{"test"})

	conn := httper.HttpConnection(":4010")
	go conn.Go(rackup)

	GetFrom("http://localhost:4010/")
	//output: Hello World
}
Пример #21
0
func Example_Basic() {
	rackup := rack.New()
	rackup.Add(templater.GetTemplates("./test_templates"))
	rackup.Add(AddLayout)
	rackup.Add(rack.Func(func(vars map[string]interface{}, next func()) {
		vars["Layout"] = "test"
		vars["Title"] = "Hello World"
		(httper.V)(vars).AppendMessageString("Hello World!")
	}))

	conn := httper.HttpConnection(":4000")
	go conn.Go(rackup)

	GetFrom("http://localhost:4000/")
	//output: <html><head><title>Hello World</title></head><body>Hello World!</body></html>
}
Пример #22
0
func init() {
	jar, err := cookiejar.New(nil)
	if err != nil {
		panic("No Cookie Jar!")
	}
	client = &http.Client{Jar: jar}
	root := NewRoot(redirecter.Redirecter{"http://localhost:5001/coins"})
	coinRoute := NewResource(&Coins{})
	root.AddRoute(coinRoute)

	rackup := rack.New()
	rackup.Add(templater.GetTemplates("./test_templates"))
	rackup.Add(sessioner.Middleware)
	rackup.Add(root)

	conn := httper.HttpConnection(":5001")
	go conn.Go(rackup)
}
Пример #23
0
func Example_Redirect() {
	rackup := rack.New()
	rackup.Add(rack.Func(func(vars map[string]interface{}, next func()) {
		h := (httper.V)(vars)
		path := h.GetRequest().URL.Path
		if path != "/" {
			h.SetMessageString(path)
		} else {
			next()
		}
	}))
	rackup.Add(Redirecter{"/redirected/"})

	conn := httper.HttpConnection(":4008")
	go conn.Go(rackup)

	GetFrom("http://localhost:4008/")
	//output: /redirected/
}
Пример #24
0
func init() {
	//set up oauth host

	hoster := &FakeProvider{
		YourURL:     "http://localhost:4006",
		YourLanding: "/callback",
		MyURL:       "http://localhost:3001",
	}

	hostconn := httper.HttpConnection(":3001")
	go hostconn.Go(hoster.Middleware())

	//set up our site
	cept := New(hoster, TokenHandlerFunc)

	rackup := rack.New()
	rackup.Add(sessioner.Middleware)
	rackup.Add(cept)

	conn := httper.HttpConnection(":4006")
	go conn.Go(rackup)
}
Пример #25
0
func (this dispatchAction) Run(vars map[string]interface{}, next func()) {
	actions := rack.New()
	actions.Add(this.action)
	switch (httper.V)(vars).GetRequest().Method {
	case "GET":
		//if it was a get, the default action should be to render the template corresponding with the action
		actions.Add(renderer.Renderer{this.routeName + "/" + this.name})
	case "POST", "PUT":
		//if it was a put or a post, we the default action should be to redirect to the affected item
		actions.Add(rack.Func(func(vars map[string]interface{}, next func()) {
			(redirecter.V)(vars).Redirect(this.descriptor.router.Route(vars))
		}))
	case "DELETE":
		actions.Add(rack.Func(func(vars map[string]interface{}, next func()) {
			delete(vars, this.varName)
			(redirecter.V)(vars).Redirect(this.descriptor.router.Route(vars))
		}))
	default:
		panic("Unknown method")
	}
	actions.Run(vars, next)
}