Skip to content

Commit

Permalink
Merge pull request #64 for v0.6 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jun 7, 2017
2 parents e0e9fbe + e577358 commit 981ec7a
Show file tree
Hide file tree
Showing 23 changed files with 486 additions and 141 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# aah web framework for Go
[![Build Status](https://travis-ci.org/go-aah/aah.svg?branch=master)](https://travis-ci.org/go-aah/aah) [![codecov](https://codecov.io/gh/go-aah/aah/branch/master/graph/badge.svg)](https://codecov.io/gh/go-aah/aah/branch/master) [![Go Report Card](https://goreportcard.com/badge/aahframework.org/aah.v0)](https://goreportcard.com/report/aahframework.org/aah.v0)
[![Powered by Go](https://img.shields.io/badge/powered_by-go-blue.svg)](https://golang.org)
[![Version](https://img.shields.io/badge/version-0.5.1-blue.svg)](https://github.com/go-aah/aah/releases/latest) [![GoDoc](https://godoc.org/aahframework.org/aah.v0?status.svg)](https://godoc.org/aahframework.org/aah.v0)
[![Version](https://img.shields.io/badge/version-0.6-blue.svg)](https://github.com/go-aah/aah/releases/latest) [![GoDoc](https://godoc.org/aahframework.org/aah.v0?status.svg)](https://godoc.org/aahframework.org/aah.v0)
[![License](https://img.shields.io/github/license/go-aah/aah.svg)](LICENSE)

***Release [v0.5.1](https://github.com/go-aah/aah/releases/latest) tagged on May 21, 2017***
***Release [v0.6](https://github.com/go-aah/aah/releases/latest) tagged on Jun 07, 2017***

aah framework - A scalable, performant, rapid development Web framework for Go.

Expand Down
4 changes: 3 additions & 1 deletion aah.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// Version no. of aah framework
const Version = "0.5.1"
const Version = "0.6"

// aah application variables
var (
Expand All @@ -38,6 +38,7 @@ var (
appSSLKey string
appIsSSLEnabled bool
appIsLetsEncrypt bool
appIsProfileProd bool
appMultipartMaxMemory int64
appPID int
appInitialized bool
Expand Down Expand Up @@ -161,6 +162,7 @@ func SetAppProfile(profile string) error {
}

appProfile = profile
appIsProfileProd = appProfile == "prod"
return nil
}

Expand Down
14 changes: 14 additions & 0 deletions aah_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package aah

import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -199,3 +201,15 @@ func TestAahBuildInfo(t *testing.T) {
assert.Equal(t, buildTime, AppBuildInfo().Date)
assert.Equal(t, "1.0.0", AppBuildInfo().Version)
}

func TestAahConfigValidation(t *testing.T) {
err := checkSSLConfigValues(true, false, "/path/to/cert.pem", "/path/to/cert.key")
assert.Equal(t, "SSL cert file not found: /path/to/cert.pem", err.Error())
fmt.Println(err)

certPath := filepath.Join(getTestdataPath(), "cert.pem")
defer ess.DeleteFiles(certPath)
_ = ioutil.WriteFile(certPath, []byte("cert.pem file"), 0755)
err = checkSSLConfigValues(true, false, certPath, "/path/to/cert.key")
assert.Equal(t, "SSL key file not found: /path/to/cert.key", err.Error())
}
18 changes: 14 additions & 4 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type (
// response.
Res ahttp.ResponseWriter

controller string
controller *controllerInfo
action *MethodInfo
target interface{}
domain *router.Domain
Expand Down Expand Up @@ -98,13 +98,23 @@ func (ctx *Context) Msgl(locale *ahttp.Locale, key string, args ...interface{})
return AppI18n().Lookup(locale, key, args...)
}

// Subdomain method returns the subdomain from the incoming request if available
// as per routes.conf. Otherwise empty string.
func (ctx *Context) Subdomain() string {
if ctx.domain.IsSubDomain {
if idx := strings.IndexByte(ctx.Req.Host, '.'); idx > 0 {
return ctx.Req.Host[:idx]
}
}
return ""
}

// Session method always returns `session.Session` object. Use `Session.IsNew`
// to identify whether sesison is newly created or restored from the request
// which was already created.
func (ctx *Context) Session() *session.Session {
if ctx.session == nil {
ctx.session = AppSessionManager().NewSession()
ctx.AddViewArg(keySessionValues, ctx.session)
}
return ctx.session
}
Expand Down Expand Up @@ -185,7 +195,7 @@ func (ctx *Context) SetMethod(method string) {
func (ctx *Context) Reset() {
ctx.Req = nil
ctx.Res = nil
ctx.controller = ""
ctx.controller = nil
ctx.action = nil
ctx.target = nil
ctx.domain = nil
Expand All @@ -209,7 +219,7 @@ func (ctx *Context) setTarget(route *router.Route) error {
return errTargetNotFound
}

ctx.controller = controller.Name()
ctx.controller = controller
ctx.action = controller.FindMethod(route.Action)
if ctx.action == nil {
return errTargetNotFound
Expand Down
23 changes: 22 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http/httptest"
"path/filepath"
"reflect"
"strings"
"testing"

"aahframework.org/ahttp.v0"
Expand Down Expand Up @@ -111,7 +112,8 @@ func TestContextSetTarget(t *testing.T) {

err1 := ctx.setTarget(&router.Route{Controller: "Level3", Action: "Testing"})
assert.Nil(t, err1)
assert.Equal(t, "Level3", ctx.controller)
assert.Equal(t, "Level3", ctx.controller.Name())
assert.True(t, strings.HasPrefix(ctx.controller.Namespace, "ahframework.org/aah.v0"))
assert.NotNil(t, ctx.action)
assert.Equal(t, "Testing", ctx.action.Name)
assert.NotNil(t, ctx.action.Parameters)
Expand Down Expand Up @@ -139,6 +141,16 @@ func TestContextSession(t *testing.T) {
assert.NotNil(t, s1.ID)
}

func TestContextSubdomain(t *testing.T) {
testSubdomainValue(t, "username1.sample.com", "username1", true)

testSubdomainValue(t, "username2.sample.com", "username2", true)

testSubdomainValue(t, "admin.username1.sample.com", "admin", true)

testSubdomainValue(t, "sample.com", "", false)
}

func TestContextAbort(t *testing.T) {
ctx := &Context{}

Expand Down Expand Up @@ -272,6 +284,15 @@ func addToCRegistry() {
AddController((*Path2)(nil), nil)
}

func testSubdomainValue(t *testing.T, host, subdomain string, isSubdomain bool) {
ctx := &Context{
Req: &ahttp.Request{Host: host},
domain: &router.Domain{IsSubDomain: isSubdomain},
}

assert.Equal(t, subdomain, ctx.Subdomain())
}

func getAahRequest(method, target, al string) *ahttp.Request {
rawReq := httptest.NewRequest(method, target, nil)
rawReq.Header.Add(ahttp.HeaderAcceptLanguage, al)
Expand Down
18 changes: 10 additions & 8 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package aah

import (
"path"
"reflect"
"strings"

Expand Down Expand Up @@ -70,10 +71,10 @@ func AddController(c interface{}, methods []*MethodInfo) {
methodMapping[strings.ToLower(method.Name)] = method
}

key := createRegistryKey(cType)
key, namespace := createRegistryKeyAndNamespace(cType)
cRegistry[key] = &controllerInfo{
Type: cType,
Namespace: ess.StripExt(key),
Namespace: namespace,
Methods: methodMapping,
EmbeddedIndexes: findEmbeddedContext(cType),
}
Expand Down Expand Up @@ -132,15 +133,16 @@ func actualType(v interface{}) reflect.Type {
return vt
}

// createRegistryKey method creates the controller registry key.
func createRegistryKey(cType reflect.Type) string {
// createRegistryKeyAndNamespace method creates the controller registry key.
func createRegistryKeyAndNamespace(cType reflect.Type) (string, string) {
namespace := cType.PkgPath()
idx := strings.Index(namespace, "controllers")
namespace = namespace[idx+11:]
if idx := strings.Index(namespace, "controllers"); idx > -1 {
namespace = namespace[idx+11:]
}

if ess.IsStrEmpty(namespace) {
return strings.ToLower(cType.Name())
return strings.ToLower(cType.Name()), ""
}

return strings.ToLower(namespace[1:] + "." + cType.Name())
return strings.ToLower(path.Join(namespace[1:], cType.Name())), namespace[1:]
}
Loading

0 comments on commit 981ec7a

Please sign in to comment.