mirror of
https://github.com/Xevion/banner.git
synced 2025-12-13 12:11:04 -06:00
Encapsulate default term selection into term.go
This commit is contained in:
12
main.go
12
main.go
@@ -270,15 +270,9 @@ func main() {
|
||||
}
|
||||
|
||||
// Term Select Pre-Search POST
|
||||
var termSelect string
|
||||
currentTerm, nextTerm := GetCurrentTerm(time.Now())
|
||||
if currentTerm == nil {
|
||||
termSelect = nextTerm.ToString()
|
||||
} else {
|
||||
termSelect = currentTerm.ToString()
|
||||
}
|
||||
log.Info().Str("term", termSelect).Str("sessionID", sessionID).Msg("Setting selected term")
|
||||
SelectTerm(termSelect)
|
||||
term := Default(time.Now()).ToString()
|
||||
log.Info().Str("term", term).Str("sessionID", sessionID).Msg("Setting selected term")
|
||||
SelectTerm(term)
|
||||
|
||||
// Close session, ensure http client closes idle connections
|
||||
defer session.Close()
|
||||
|
||||
9
term.go
9
term.go
@@ -129,3 +129,12 @@ func (term Term) ToString() string {
|
||||
|
||||
return fmt.Sprintf("%d%s", term.Year, season)
|
||||
}
|
||||
|
||||
// Default chooses the default term, which is the current term if it exists, otherwise the next term.
|
||||
func Default(t time.Time) Term {
|
||||
currentTerm, nextTerm := GetCurrentTerm(t)
|
||||
if currentTerm == nil {
|
||||
return *nextTerm
|
||||
}
|
||||
return *currentTerm
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user