Skip to content

Commit

Permalink
Merge pull request #10 for v0.8.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jun 21, 2018
2 parents 10dfe36 + 1ce0c2c commit c79d02c
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 35 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ branches:
# skip tags build, we are building branch and master that is enough for
# consistenty check and release. Let's use Travis CI resources optimally
# for aah framework.
- /^v[0-9]\.[0-9]/
- /^v[0-9.]+$/

go:
- 1.8
- 1.9
- 1.9.x
- 1.10.x
- tip

go_import_path: aahframework.org/essentials.v0

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

script:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 13 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
# essentials - aah framework
[![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)
[![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)
<p align="center">
<img src="https://cdn.aahframework.org/assets/img/aah-logo-64x64.png" />
<h2 align="center">Essentials by aah framework</h2>
<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>
</p>
<p align="center">
<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>
</p>

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

`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:
* `v0.8.0` [released](https://github.com/go-aah/essentials/releases/latest) and tagged on Jun 20, 2018.

* filepath
* GUID (Globally Unique Identifier - Mongo Object ID algorithm)
* random string, random byte generation at fixed length
* go
* io
* os
* reflect
* string
* encode
* archive (zip)
## Installation

*`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.*

# Installation
#### Stable Version - Production Ready
```sh
# install the library
```bash
go get -u aahframework.org/essentials.v0
```

Visit official website https://aahframework.org to learn more.
Visit official website https://aahframework.org to learn more about `aah` framework.
11 changes: 11 additions & 0 deletions essentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// aahframework.org/essentials source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

package ess

// Valuer interface is general purpose to `Set` and `Get` operations.
type Valuer interface {
Get(key string) interface{}
Set(key string, value interface{})
}
5 changes: 4 additions & 1 deletion filepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func Walk(srcDir string, walkFn filepath.WalkFunc) error {

func doWalk(fname string, linkName string, walkFn filepath.WalkFunc) error {
fsWalkFn := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

var name string
name, err = filepath.Rel(fname, path)
if err != nil {
Expand All @@ -135,7 +139,6 @@ func doWalk(fname string, linkName string, walkFn filepath.WalkFunc) error {
return err
}

// https://github.com/golang/go/blob/master/src/path/filepath/path.go#L392
info, err = os.Lstat(symlinkPath)
if err != nil {
return walkFn(path, info, err)
Expand Down
11 changes: 7 additions & 4 deletions guid.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ var (
// Package methods
//___________________________________

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

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

Expand All @@ -97,6 +99,7 @@ func readMachineID() []byte {
return id
}

// return nil, errors.New("guid: unable to get hostname and random bytes")
// To initialize package unexported variable 'machineID'.
// This panic would happen at program startup, so no worries at runtime panic.
panic(errors.New("ess - guid: unable to get hostname and random bytes"))
}
3 changes: 3 additions & 0 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package ess

import "strings"

// StringEmpty is empty string constant. Using `ess.StringEmpty` instead of "".
const StringEmpty = ""

// IsStrEmpty returns true if strings is empty otherwise false
func IsStrEmpty(v string) bool {
return len(strings.TrimSpace(v)) == 0
Expand Down
28 changes: 28 additions & 0 deletions url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// aahframework.org/essentials source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

package ess

import "net/url"

// IsVaildURL method returns true if given raw URL gets parsed without any errors
// otherwise false.
func IsVaildURL(rawurl string) bool {
_, err := url.Parse(rawurl)
return err == nil
}

// IsRelativeURL method returns true if given raw URL is relative URL otherwise false.
func IsRelativeURL(rawurl string) bool {
return !IsAbsURL(rawurl)
}

// IsAbsURL method returns true if given raw URL is absolute URL otherwise false.
func IsAbsURL(rawurl string) bool {
u, err := url.Parse(rawurl)
if err != nil {
return false
}
return u.IsAbs()
}
54 changes: 54 additions & 0 deletions url_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// aahframework.org/essentials source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

package ess

import (
"testing"

"aahframework.org/test.v0/assert"
)

func TestURLValue(t *testing.T) {
t.Log("Valid URLs")
for _, u := range []string{
"https://aahframework.org",
"/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",
"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",
"https://godoc.org/golang.org/x/oauth2",
"http://godoc.org/",
} {
assert.True(t, IsVaildURL(u))
}

t.Log("Absolute URL")
for _, u := range []string{
"https://aahframework.org",
"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",
"https://godoc.org/golang.org/x/oauth2",
"http://godoc.org/",
} {
assert.True(t, IsAbsURL(u))
}

t.Log("Error - Absolute URL")
for _, u := range []string{
"://aahframework.org",
"://",
"http",
"https",
} {
assert.False(t, IsAbsURL(u))
}

t.Log("Relative URL")
for _, u := range []string{
"/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",
"/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",
"/golang.org/x/oauth2",
} {
assert.True(t, IsRelativeURL(u))
}

}
6 changes: 3 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// go-aah/essentials source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

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

// Version no. of essentials library
var Version = "0.7"
var Version = "0.8.0"

0 comments on commit c79d02c

Please sign in to comment.