Helpers

[[toc]]

Available Methods

Paths

Time

Paths

path.App()

The path.App() function returns the path to your application's app directory. You may also use the path.App() function to generate a path to a file relative to the application directory:

import "github.com/goravel/framework/support/path"

path := path.App()
path := path.App("http/controllers/controller.go")

path.Base()

The path.Base() function returns the path to your application's root directory. You may also use the path.Base() function to generate a path to a given file relative to the project root directory:

path := path.Base()
path := path.Base("'vendor/bin'")

path.Config()

The path.Config() function returns the path to your application's config directory. You may also use the path.Config() function to generate a path to a given file within the application's configuration directory:

path := path.Config()
path := path.Config("app.go")

path.Database()

The path.Database() function returns the path to your application's database directory. You may also use the path.Database() function to generate a path to a given file within the database directory:

path := path.Database()
path := path.Database("factories/user_factory.go")

path.Storage()

The path.Storage() function returns the path to your application's storage directory. You may also use the path.Storage() function to generate a path to a given file within the storage directory:

path := path.Storage()
path := path.Storage("app/file.txt")

path.Public()

The path.Public() function returns the path to your application's public directory. You may also use the path.Public() function to generate a path to a given file within the public directory:

path := path.Public()
path := path.Public("css/app.css")

Time

The carbon module of Goravel is an expansion by golang-module/carbon, the main feature is the realization of time backtracking, please look into the official documentation for detail.

carbon.Now()

Get current time:

import "github.com/goravel/framework/carbon"

carbon.Now()

carbon.SetTimezone()

Set timezone:

carbon.SetTimezone(carbon.UTC)

carbon.Parse()

Get Carbon object by String:

carbon.Parse("2020-08-05 13:14:15")

carbon.FromTimestamp()

Get Carbon Object by timestamp:

carbon.FromTimestamp(1577836800)

carbon.FromDateTime()

Get Carbon Object by date time:

carbon.FromDateTime(2020, 1, 1, 0, 0, 0)

carbon.FromDate()

Get Carbon Object by date:

carbon.FromDate(2020, 1, 1)

carbon.FromTime()

Get Carbon Object by time:

carbon.FromTime(0, 0, 0)

carbon.FromStdTime()

Get Carbon Object by time.Time:

carbon.FromStdTime(time.Now())

carbon.IsTestNow()

Determine whether the time is a test value:

carbon.IsTestNow()

carbon.SetTestNow()

Set the time to a test value:

carbon.SetTestNow(carbon.Now())

carbon.UnsetTestNow()

Restore the time to a normal value:

carbon.UnsetTestNow()

Last updated