Sort out (cleanup?) setting.NewServices and setting.NewContext #564

Closed
opened 2025-11-02 03:28:19 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @strk on GitHub (Mar 22, 2017).

While trying to implement cross-section dependencies (see https://github.com/go-gitea/gitea/pull/1365#issuecomment-288365376) I found myself unable to understand the NewContext and NewServices functions in the setttings module (modules/setting/setting.go).

As those two functions are exposed and called by different places in code at different times, and each read sections of the app.ini into global variables, I'm unable to have one section variable default depend on the value of another setting.

Does anyone see why it makes sense for app.ini parsing to be spread across different places rather than having a single "settings" object to hold up all variables ?

Originally created by @strk on GitHub (Mar 22, 2017). While trying to implement cross-section dependencies (see https://github.com/go-gitea/gitea/pull/1365#issuecomment-288365376) I found myself unable to understand the `NewContext` and `NewServices` functions in the `setttings` module (modules/setting/setting.go). As those two functions are exposed and called by different places in code at different times, and each read sections of the `app.ini` into global variables, I'm unable to have one section variable default depend on the value of another setting. Does anyone see why it makes sense for `app.ini` parsing to be spread across different places rather than having a single "settings" object to hold up all variables ?
GiteaMirror added the issue/stale label 2025-11-02 03:28:19 -06:00
Author
Owner

@strk commented on GitHub (Mar 22, 2017):

All callers of setting.NewServices() also call setting.NewContext() before that:

  • cmd/dump.go:
        setting.NewContext()                                                    
        setting.NewServices() // cannot access session settings otherwise  
  • routers/init.go:
    • in GlobalInit():
     setting.NewContext()
     setting.NewServices() -- via local NewServices function

But there are some callers of setting.NewContext() that do not call setting.NewServices():

  • cmd/admin.go
  • cmd/serv.go
  • models/ssh_key_test.go
@strk commented on GitHub (Mar 22, 2017): All callers of `setting.NewServices()` also call `setting.NewContext()` before that: - ` cmd/dump.go`: ``` setting.NewContext() setting.NewServices() // cannot access session settings otherwise ``` - `routers/init.go`: - in GlobalInit(): ``` setting.NewContext() setting.NewServices() -- via local NewServices function ```` But there are some callers of `setting.NewContext()` that do not call `setting.NewServices()`: - cmd/admin.go - cmd/serv.go - models/ssh_key_test.go
Author
Owner

@stale[bot] commented on GitHub (Feb 16, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Feb 16, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Mar 2, 2019):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Mar 2, 2019): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#564