Skip to content

Commit c79d02c

Browse files
authored
Merge pull request #10 for v0.8.0 Release
2 parents 10dfe36 + 1ce0c2c commit c79d02c

10 files changed

+127
-35
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ branches:
77
# skip tags build, we are building branch and master that is enough for
88
# consistenty check and release. Let's use Travis CI resources optimally
99
# for aah framework.
10-
- /^v[0-9]\.[0-9]/
10+
- /^v[0-9.]+$/
1111

1212
go:
13-
- 1.8
14-
- 1.9
13+
- 1.9.x
14+
- 1.10.x
1515
- tip
1616

1717
go_import_path: aahframework.org/essentials.v0
1818

1919
install:
20-
- git config --global http.https://aahframework.org.followRedirects true
2120
- go get -t -v ./...
2221

2322
script:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016-2017 Jeevanandam M., https://myjeeva.com <[email protected]>
3+
Copyright (c) 2016-2018 Jeevanandam M., https://myjeeva.com <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
# essentials - aah framework
2-
[![Build Status](https://travis-ci.org/go-aah/essentials.svg?branch=master)](https://travis-ci.org/go-aah/essentials) [![codecov](https://codecov.io/gh/go-aah/essentials/branch/master/graph/badge.svg)](https://codecov.io/gh/go-aah/essentials/branch/master) [![Go Report Card](https://goreportcard.com/badge/aahframework.org/essentials.v0)](https://goreportcard.com/report/aahframework.org/essentials.v0)
3-
[![Version](https://img.shields.io/badge/version-0.7-blue.svg)](https://github.com/go-aah/essentials/releases/latest) [![GoDoc](https://godoc.org/aahframework.org/essentials.v0?status.svg)](https://godoc.org/aahframework.org/essentials.v0) [![License](https://img.shields.io/github/license/go-aah/essentials.svg)](LICENSE)
1+
<p align="center">
2+
<img src="https://cdn.aahframework.org/assets/img/aah-logo-64x64.png" />
3+
<h2 align="center">Essentials by aah framework</h2>
4+
<p>Essentials contains simple & useful util functions for Go. aah framework utilizes essentials (aka `ess`) library across. Essentials library complements to standard packages, refer Godoc to know more.</p>
5+
</p>
6+
<p align="center">
7+
<p align="center"><a href="https://travis-ci.org/go-aah/essentials"><img src="https://travis-ci.org/go-aah/essentials.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/go-aah/essentials/branch/master"><img src="https://codecov.io/gh/go-aah/essentials/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/aahframework.org/essentials.v0"><img src="https://goreportcard.com/badge/aahframework.org/essentials.v0" alt="Go Report Card"></a> <a href="https://github.com/go-aah/essentials/releases/latest"><img src="https://img.shields.io/badge/version-0.8.0-blue.svg" alt="Release Version"></a> <a href="https://godoc.org/aahframework.org/essentials.v0"><img src="https://godoc.org/aahframework.org/essentials.v0?status.svg" alt="Godoc"></a> <a href="https://twitter.com/aahframework"><img src="https://img.shields.io/badge/[email protected]" alt="Twitter @aahframework"></a></p>
8+
</p>
49

5-
***v0.7 [released](https://github.com/go-aah/essentials/releases/latest) and tagged on Sep 29, 2017***
10+
### News
611

7-
`essentials` contains simple & useful utils methods for Go. aah framework utilizes essentials (aka `ess`) library across. Essentials library complements with handy methods, refer godoc to know more about methods:
12+
* `v0.8.0` [released](https://github.com/go-aah/essentials/releases/latest) and tagged on Jun 20, 2018.
813

9-
* filepath
10-
* GUID (Globally Unique Identifier - Mongo Object ID algorithm)
11-
* random string, random byte generation at fixed length
12-
* go
13-
* io
14-
* os
15-
* reflect
16-
* string
17-
* encode
18-
* archive (zip)
14+
## Installation
1915

20-
*`essentials` developed for aah framework. However, it's an independent library, can be used separately with any `Go` language project. Feel free to use it.*
21-
22-
# Installation
23-
#### Stable Version - Production Ready
24-
```sh
25-
# install the library
16+
```bash
2617
go get -u aahframework.org/essentials.v0
2718
```
2819

29-
Visit official website https://aahframework.org to learn more.
20+
Visit official website https://aahframework.org to learn more about `aah` framework.

essentials.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
2+
// aahframework.org/essentials source code and usage is governed by a MIT style
3+
// license that can be found in the LICENSE file.
4+
5+
package ess
6+
7+
// Valuer interface is general purpose to `Set` and `Get` operations.
8+
type Valuer interface {
9+
Get(key string) interface{}
10+
Set(key string, value interface{})
11+
}

filepath.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func Walk(srcDir string, walkFn filepath.WalkFunc) error {
120120

121121
func doWalk(fname string, linkName string, walkFn filepath.WalkFunc) error {
122122
fsWalkFn := func(path string, info os.FileInfo, err error) error {
123+
if err != nil {
124+
return err
125+
}
126+
123127
var name string
124128
name, err = filepath.Rel(fname, path)
125129
if err != nil {
@@ -135,7 +139,6 @@ func doWalk(fname string, linkName string, walkFn filepath.WalkFunc) error {
135139
return err
136140
}
137141

138-
// https://github.com/golang/go/blob/master/src/path/filepath/path.go#L392
139142
info, err = os.Lstat(symlinkPath)
140143
if err != nil {
141144
return walkFn(path, info, err)

guid.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ var (
3838
// Package methods
3939
//___________________________________
4040

41-
// NewGUID method returns a new Globally Unique identifier (GUID).
41+
// NewGUID method returns a new Globally Unique Identifier (GUID).
4242
//
4343
// The 12-byte `UniqueId` consists of-
4444
// - 4-byte value representing the seconds since the Unix epoch,
4545
// - 3-byte machine identifier,
4646
// - 2-byte process id, and
4747
// - 3-byte counter, starting with a random value.
4848
//
49-
// NewGUID generation using Mongo Object ID algorithm to generate globally
50-
// unique ids - https://docs.mongodb.com/manual/reference/method/ObjectId/
49+
// Uses Mongo Object ID algorithm to generate globally unique ids -
50+
// https://docs.mongodb.com/manual/reference/method/ObjectId/
5151
func NewGUID() string {
5252
var b [12]byte
5353
// Timestamp, 4 bytes, big endian
@@ -77,6 +77,8 @@ func readRandomUint32() uint32 {
7777
return (uint32(b[0]) << 0) | (uint32(b[1]) << 8) | (uint32(b[2]) << 16) | (uint32(b[3]) << 24)
7878
}
7979

80+
// To initialize package unexported variable 'guidCounter'.
81+
// This panic would happen at program startup, so no worries at runtime panic.
8082
panic(errors.New("ess - guid: unable to generate random object id"))
8183
}
8284

@@ -97,6 +99,7 @@ func readMachineID() []byte {
9799
return id
98100
}
99101

100-
// return nil, errors.New("guid: unable to get hostname and random bytes")
102+
// To initialize package unexported variable 'machineID'.
103+
// This panic would happen at program startup, so no worries at runtime panic.
101104
panic(errors.New("ess - guid: unable to get hostname and random bytes"))
102105
}

string.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package ess
66

77
import "strings"
88

9+
// StringEmpty is empty string constant. Using `ess.StringEmpty` instead of "".
10+
const StringEmpty = ""
11+
912
// IsStrEmpty returns true if strings is empty otherwise false
1013
func IsStrEmpty(v string) bool {
1114
return len(strings.TrimSpace(v)) == 0

url.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
2+
// aahframework.org/essentials source code and usage is governed by a MIT style
3+
// license that can be found in the LICENSE file.
4+
5+
package ess
6+
7+
import "net/url"
8+
9+
// IsVaildURL method returns true if given raw URL gets parsed without any errors
10+
// otherwise false.
11+
func IsVaildURL(rawurl string) bool {
12+
_, err := url.Parse(rawurl)
13+
return err == nil
14+
}
15+
16+
// IsRelativeURL method returns true if given raw URL is relative URL otherwise false.
17+
func IsRelativeURL(rawurl string) bool {
18+
return !IsAbsURL(rawurl)
19+
}
20+
21+
// IsAbsURL method returns true if given raw URL is absolute URL otherwise false.
22+
func IsAbsURL(rawurl string) bool {
23+
u, err := url.Parse(rawurl)
24+
if err != nil {
25+
return false
26+
}
27+
return u.IsAbs()
28+
}

url_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
2+
// aahframework.org/essentials source code and usage is governed by a MIT style
3+
// license that can be found in the LICENSE file.
4+
5+
package ess
6+
7+
import (
8+
"testing"
9+
10+
"aahframework.org/test.v0/assert"
11+
)
12+
13+
func TestURLValue(t *testing.T) {
14+
t.Log("Valid URLs")
15+
for _, u := range []string{
16+
"https://aahframework.org",
17+
"/facebook-auth/callback?code=AQD5-i29_Vn7fNg8VgcV-Uzk_QNO1sx6yO-tJvkRiFaGs1n-wnCxUnvLX0V2q25Tx7JRZAiTds2-DIKrDb8jPEdGquMCedQ_mpMZQxsHmPYeg_cP1Xjy2jHooK-1ZDJZQHXtDSL8FA7r3nVA7WcrCuLZrlrgXq8LnOSAil3oMD-RqPix-nI576GvAPGgiXo6ep_AfS2GaF8A8TOTwl2iwEjB74F23yEukNpz5tmDJVfH02qtrGECuDfaAEPc-4u2wVIIWKCWy3oEEeoEr4zBdzsMtUR1FP3X5yUm0_yAYFP3taAPrpM-5UqtJWmUgaOY-U0&state=72du0BBFIPjW4PsWcI21SccfRX-EkojC4dZ49MYJZac",
18+
"https://www.facebook.com/dialog/oauth?client_id=182958108394860&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Ffacebook-auth%2Fcallback&response_type=code&scope=public_profile+email&state=72du0BBFIPjW4PsWcI21SccfRX-EkojC4dZ49MYJZac",
19+
"https://godoc.org/golang.org/x/oauth2",
20+
"http://godoc.org/",
21+
} {
22+
assert.True(t, IsVaildURL(u))
23+
}
24+
25+
t.Log("Absolute URL")
26+
for _, u := range []string{
27+
"https://aahframework.org",
28+
"https://www.facebook.com/dialog/oauth?client_id=182958108394860&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Ffacebook-auth%2Fcallback&response_type=code&scope=public_profile+email&state=72du0BBFIPjW4PsWcI21SccfRX-EkojC4dZ49MYJZac",
29+
"https://godoc.org/golang.org/x/oauth2",
30+
"http://godoc.org/",
31+
} {
32+
assert.True(t, IsAbsURL(u))
33+
}
34+
35+
t.Log("Error - Absolute URL")
36+
for _, u := range []string{
37+
"://aahframework.org",
38+
"://",
39+
"http",
40+
"https",
41+
} {
42+
assert.False(t, IsAbsURL(u))
43+
}
44+
45+
t.Log("Relative URL")
46+
for _, u := range []string{
47+
"/facebook-auth/callback?code=AQD5-i29_Vn7fNg8VgcV-Uzk_QNO1sx6yO-tJvkRiFaGs1n-wnCxUnvLX0V2q25Tx7JRZAiTds2-DIKrDb8jPEdGquMCedQ_mpMZQxsHmPYeg_cP1Xjy2jHooK-1ZDJZQHXtDSL8FA7r3nVA7WcrCuLZrlrgXq8LnOSAil3oMD-RqPix-nI576GvAPGgiXo6ep_AfS2GaF8A8TOTwl2iwEjB74F23yEukNpz5tmDJVfH02qtrGECuDfaAEPc-4u2wVIIWKCWy3oEEeoEr4zBdzsMtUR1FP3X5yUm0_yAYFP3taAPrpM-5UqtJWmUgaOY-U0&state=72du0BBFIPjW4PsWcI21SccfRX-EkojC4dZ49MYJZac",
48+
"/dialog/oauth?client_id=182958108394860&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Ffacebook-auth%2Fcallback&response_type=code&scope=public_profile+email&state=72du0BBFIPjW4PsWcI21SccfRX-EkojC4dZ49MYJZac",
49+
"/golang.org/x/oauth2",
50+
} {
51+
assert.True(t, IsRelativeURL(u))
52+
}
53+
54+
}

version.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// go-aah/essentials source code and usage is governed by a MIT style
33
// license that can be found in the LICENSE file.
44

5-
// Package ess provides simple & useful utils for Go. aah framework utilizes
6-
// essentials library across. It's pretty handy you can use it too :)
5+
// Package ess provides simple & useful util functions for Go. aah framework
6+
// utilizes essentials library across.
77
package ess
88

99
// Version no. of essentials library
10-
var Version = "0.7"
10+
var Version = "0.8.0"

0 commit comments

Comments
 (0)