ClientSession
The ClientSession
represents a session for the ClientDevice. It can be manipulated using the SessionsMgrApi. To get an instance of ClientSession
, you can use the CreateSession, CurrSession or GetSession methods from SessionMgrApi. For example:
func (w http.ResponseWriter, r *http.Request) {
clnt, _ := api.Http().GetClientDevice(r)
session, _ := api.SessionsMgr().CurrSession(clnt)
}
ClientSession Methods
The following methods are available in ClientSession
.
Provider
Returns the session provider name. The provider name is a string
value.
Type
Returns the session type. The session type is a uint8
value.
The available session types are:
Value | Description |
---|---|
0 | Represents a time session in seconds. Time sessions are sessions that expire when the allocated time is consumed. |
1 | Represents a data session in in Megabytes. Data sessions are sessions that expire when the allocated data is consumed. |
2 | Represents a time_or_data session. Time or data sessions are sessions that are limited by time or data, whichever is consumed first. |
TimeSecs
Returns the allocated session time in seconds. This is only applicable for time
and time_or_data
sessions.
DataMb
Returns the allocated session data in Megabytes. This is only applicable for data
and time_or_data
sessions.
TimeConsumption
Returns the consumed session time in seconds. The return type is a uint
value. This is only applicable for time
and time_or_data
sessions. It is used to track the consumed time of the session.
DataConsumption
Returns the consumed session data in Megabytes. The return type is a float64
value. This is only applicable for data
and time_or_data
sessions. It is used to track the consumed data of the session.
RemainingTime
Returns the remaining session time in seconds. The return type is a uint
value and is calculated by subtracting the time consumption from the allocated time. This is only applicable for time
and time_or_data
sessions.
RemainingData
Returns the remaining session data in Megabytes. The return type is a float64
value and is calculated by subtracting the data consumption from the allocated data. This is only applicable for data
and time_or_data
sessions.
StartedAt
Returns a *time.Time
value representing the time the session started. A nil
value is returned if the session has not started.
CreatedAt
Returns a time.Time
value representing the time the session was created.
ExpDays
Returns a *uint
value representing the expiration days after the session is started. A nil
value is returned if the session does not have expiration date.
ExpiresAt
Returns a *time.Time
value representing the time the session will expire. The expiration time is calculated based on the session start time and the expiration days. A nil
value is returned if the session does not have expiration date.
DownMbits
Returns the download speed of the session in Megabits per second (mbps).
UpMbits
Returns the upload speed of the session in Megabits per second (mbps).
UseGlobalSpeed
Returns a bool
value indicating if the session uses the global bandwidth settings for the network interface which the ClientDevice is connected.
IncTimeCons
Increments the consumed session time by n
seconds. The new value is not saved until the save method is called.
IncDataCons
Increments the consumed session data by n
Megabytes. The new value is not saved until the save method is called.
SetTimeSecs
Sets the allocated session time in seconds. This is only applicable for time
and time_or_data
sessions. The new value is not saved until the save method is called.
SetDataMb
Sets the allocated session data in Megabytes. This is only applicable for data
and time_or_data
sessions. The new value is not saved until the save method is called.
SetTimeCons
Sets the consumed session time in seconds. This is only applicable for time
and time_or_data
sessions. The new value is not saved until the save method is called.
SetDataCons
Sets the consumed session data in Megabytes. This is only applicable for data
and time_or_data
sessions. The new value is not saved until the save method is called.
SetStartedAt
Sets the session start time. The new value is not saved until the save method is called.
SetExpDays
Sets the expiration days after the session is started. The new value is not saved until the save method is called.
SetDownMbits
Sets the download speed of the session in Megabits per second (mbps). The new value is not saved until the save method is called.
SetUpMbits
Sets the upload speed of the session in Megabits per second (mbps). The new value is not saved until the save method is called.
SetUseGlobalSpeed
Sets a bool
value indicating if the session uses the global bandwidth settings for the network interface which the ClientDevice is connected. The new value is not saved until the save method is called.
Save
Save the session changes to the database.
Reload
Reload the session data from the database.