2017-11-16 20:31:20 +00:00
|
|
|
// Copyright © 2016 Abcum Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package fncs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/abcum/surreal/util/fake"
|
|
|
|
)
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func rand(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.DecimalBetween(0, 1), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randBool(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.Bool(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randGuid(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-27 11:35:26 +00:00
|
|
|
return fake.Guid(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randUuid(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.Uuid(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func randEnum(ctx context.Context, args ...interface{}) (interface{}, error) {
|
|
|
|
switch len(args) {
|
|
|
|
case 0:
|
|
|
|
return nil, nil
|
|
|
|
default:
|
|
|
|
return args[fake.IntegerBetween(0, len(args))], nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randTime(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
switch len(args) {
|
|
|
|
case 2:
|
|
|
|
if b, ok := ensureTime(args[0]); ok {
|
|
|
|
if e, ok := ensureTime(args[1]); ok {
|
|
|
|
return fake.TimeBetween(b, e), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fake.Time(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randString(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
switch len(args) {
|
|
|
|
case 1:
|
|
|
|
if l, ok := ensureInt(args[0]); ok {
|
|
|
|
return fake.StringLength(int(l)), nil
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
if b, ok := ensureInt(args[0]); ok {
|
|
|
|
if e, ok := ensureInt(args[1]); ok {
|
|
|
|
return fake.StringBetween(int(b), int(e)), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fake.String(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randInteger(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
switch len(args) {
|
|
|
|
case 2:
|
|
|
|
if b, ok := ensureInt(args[0]); ok {
|
|
|
|
if e, ok := ensureInt(args[1]); ok {
|
|
|
|
return float64(fake.IntegerBetween(int(b), int(e))), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return float64(fake.Integer()), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randDecimal(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
switch len(args) {
|
|
|
|
case 2:
|
|
|
|
if b, ok := ensureFloat(args[0]); ok {
|
|
|
|
if e, ok := ensureFloat(args[1]); ok {
|
|
|
|
return fake.DecimalBetween(b, e), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fake.Decimal(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randWord(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.Word(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randSentence(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
switch len(args) {
|
|
|
|
case 2:
|
|
|
|
if b, ok := ensureInt(args[0]); ok {
|
|
|
|
if e, ok := ensureInt(args[1]); ok {
|
|
|
|
return fake.SentenceBetween(int(b), int(e)), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fake.Sentence(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randParagraph(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
switch len(args) {
|
|
|
|
case 2:
|
|
|
|
if b, ok := ensureInt(args[0]); ok {
|
|
|
|
if e, ok := ensureInt(args[1]); ok {
|
|
|
|
return fake.ParagraphBetween(int(b), int(e)), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fake.Paragraph(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randPersonEmail(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.PersonEmail(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randPersonPhone(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.PersonPhone(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randPersonFullname(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.PersonFullname(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randPersonFirstname(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.PersonFirstname(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randPersonLastname(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.PersonLastname(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randPersonUsername(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.PersonUsername(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randPersonJobtitle(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.PersonJobtitle(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randCompanyName(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.CompanyName(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randCompanyIndustry(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.CompanyIndustry(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationName(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationName(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationAddress(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationAddress(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationStreet(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationStreet(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationCity(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationCity(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationState(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationState(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationCounty(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationCounty(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationZipcode(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationZipcode(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationPostcode(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationPostcode(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationCountry(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationCountry(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationAltitude(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationAltitude(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationLatitude(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationLatitude(), nil
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:35:46 +00:00
|
|
|
func randLocationLongitude(ctx context.Context, args ...interface{}) (interface{}, error) {
|
2017-11-16 20:31:20 +00:00
|
|
|
return fake.LocationLongitude(), nil
|
|
|
|
}
|