-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Provide self-registering storage system #12978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
techknowlogick
merged 10 commits into
go-gitea:master
from
zeripath:lunny/storage_config-self-register
Oct 13, 2020
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1b352a4
Provide self-registering storage system
zeripath 266283c
More simplification
zeripath 2b05f9e
Merge remote-tracking branch 'origin/master' into lunny/storage_confi…
zeripath 7f2f6fe
Remove old strings from setting
zeripath 9be4a31
Merge branch 'master' into lunny/storage_config-self-register
zeripath f572e2f
Merge remote-tracking branch 'origin/master' into lunny/storage_confi…
zeripath 714c2e3
Merge remote-tracking branch 'origin/master' into lunny/storage_confi…
zeripath 0142c43
oops attachments not attachment
zeripath f0ed79c
Merge branch 'master' into lunny/storage_config-self-register
lunny 696b9b6
Merge branch 'master' into lunny/storage_config-self-register
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -760,7 +760,6 @@ func NewContext() { | |
} | ||
} | ||
|
||
newStorageService() | ||
newAttachmentService() | ||
newLFSService() | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package storage | ||
|
||
import ( | ||
"encoding/json" | ||
"reflect" | ||
) | ||
|
||
// Mappable represents an interface that can MapTo another interface | ||
type Mappable interface { | ||
MapTo(v interface{}) error | ||
} | ||
|
||
// toConfig will attempt to convert a given configuration cfg into the provided exemplar type. | ||
// | ||
// It will tolerate the cfg being passed as a []byte or string of a json representation of the | ||
// exemplar or the correct type of the exemplar itself | ||
func toConfig(exemplar, cfg interface{}) (interface{}, error) { | ||
|
||
// First of all check if we've got the same type as the exemplar - if so it's all fine. | ||
if reflect.TypeOf(cfg).AssignableTo(reflect.TypeOf(exemplar)) { | ||
return cfg, nil | ||
} | ||
|
||
// Now if not - does it provide a MapTo function we can try? | ||
if mappable, ok := cfg.(Mappable); ok { | ||
newVal := reflect.New(reflect.TypeOf(exemplar)) | ||
if err := mappable.MapTo(newVal.Interface()); err == nil { | ||
return newVal.Elem().Interface(), nil | ||
} | ||
// MapTo has failed us ... let's try the json route ... | ||
} | ||
|
||
// OK we've been passed a byte array right? | ||
configBytes, ok := cfg.([]byte) | ||
if !ok { | ||
// oh ... it's a string then? | ||
var configStr string | ||
|
||
configStr, ok = cfg.(string) | ||
configBytes = []byte(configStr) | ||
} | ||
if !ok { | ||
// hmm ... can we marshal it to json? | ||
var err error | ||
|
||
configBytes, err = json.Marshal(cfg) | ||
ok = (err == nil) | ||
} | ||
if !ok { | ||
// no ... we've tried hard enough at this point - throw an error! | ||
return nil, ErrInvalidConfiguration{cfg: cfg} | ||
} | ||
|
||
// OK unmarshal the byte array into a new copy of the exemplar | ||
newVal := reflect.New(reflect.TypeOf(exemplar)) | ||
if err := json.Unmarshal(configBytes, newVal.Interface()); err != nil { | ||
// If we can't unmarshal it then return an error! | ||
return nil, ErrInvalidConfiguration{cfg: cfg, err: err} | ||
} | ||
return newVal.Elem().Interface(), nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.