github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/databases/orm/models_boot.go (about)

     1  // The original package is migrated from beego and modified, you can find orignal from following link:
     2  //    "github.com/beego/beego/"
     3  //
     4  // Copyright 2023 IAC. All Rights Reserved.
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //      http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package orm
    19  
    20  // RegisterModel register models
    21  func RegisterModel(models ...interface{}) {
    22  	RegisterModelWithPrefix("", models...)
    23  }
    24  
    25  // RegisterModelWithPrefix register models with a prefix
    26  func RegisterModelWithPrefix(prefix string, models ...interface{}) {
    27  	if err := defaultModelCache.register(prefix, true, models...); err != nil {
    28  		panic(err)
    29  	}
    30  }
    31  
    32  // RegisterModelWithSuffix register models with a suffix
    33  func RegisterModelWithSuffix(suffix string, models ...interface{}) {
    34  	if err := defaultModelCache.register(suffix, false, models...); err != nil {
    35  		panic(err)
    36  	}
    37  }
    38  
    39  // BootStrap bootstrap models.
    40  // make all model parsed and can not add more models
    41  func BootStrap() {
    42  	defaultModelCache.bootstrap()
    43  }