sav-utils
sav utils library
npm
php
CaseConvert
use SavUtil\CaseConvert;
CaseConvert::convert('camel', 'HelloWorld'); // helloWorld
CaseConvert::convert('pascal', 'Hello-World'); // HelloWorld
CaseConvert::convert('snake', 'HelloWorld'); // hello_world
CaseConvert::convert('hyphen', 'HelloWorld'); // hello-world
// same as above
CaseConvert::pascalCase('HelloWorld');
CaseConvert::pascalCase('Hello-World');
CaseConvert::snakeCase('HelloWorld');
CaseConvert::hyphenCase('HelloWorld');
DateTime
use SavUtil\DateTime;
DateTime::localTime();
DateTime::utcTime();
DateTime::localToUtc();
DateTime::utcToLocal();
Request
use SavUtil\Request;
$res = Request::fetch('http://example.com');
$res->status == 200;
is_array($res->headers);
is_string($res->response);
Request::fetch(array(
'url' => 'http://example.com',
'data' => array(),
'headers' => array(),
'options' => array(
// default Options
'timeout' => 10,
'connect_timeout' => 10,
'useragent' => 'curl', // ua
'type' => 'GET', // method
'dataType' => '', // empty|json
'assoc' => true, // json assoc array
'filename' => false, // save file
'verify' => false, // ssl verify
'verifyname' => false, // ssl verifyname
),
));
Request::fetchAll(array(
"requestA" => array(
"url" => 'http://example.com',
"headers" => array(),
"data" => array(),
"options" => array(),
),
"requestB" => array(
"url" => 'http://example.com',
"headers" => array(),
"data" => array(),
"options" => array(),
),
), array(
"timeout" => 20,
));
go
密码散列
-
passwd.Create
- 类似php的
password_hash
- 目前只提供bcrypt算法
- 类似php的
-
passwd.Verify
- 类似php的
password_verify
- 类似php的
-
passwd.IsCurrent
- 类似php的
password_needs_rehash
- 由于只有一个bcrypt所以暂时没用
- 类似php的
package main
import (
"github.com/savgo/sav-util/passwd"
"fmt"
)
func main() {
plaintext := "password"
pwd, _ := passwd.Create(plaintext)
isValid, _ := passwd.Verify(plaintext, pwd)
fmt.Println(pwd) // $2a$08$...
fmt.Println(len(pwd)) // 60
fmt.Println(isValid) // true
}