github.com/gogf/gf@v1.16.9/frame/g/g_object.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package g
     8  
     9  import (
    10  	"github.com/gogf/gf/database/gdb"
    11  	"github.com/gogf/gf/database/gredis"
    12  	"github.com/gogf/gf/frame/gins"
    13  	"github.com/gogf/gf/i18n/gi18n"
    14  	"github.com/gogf/gf/net/ghttp"
    15  	"github.com/gogf/gf/net/gtcp"
    16  	"github.com/gogf/gf/net/gudp"
    17  	"github.com/gogf/gf/os/gcfg"
    18  	"github.com/gogf/gf/os/glog"
    19  	"github.com/gogf/gf/os/gres"
    20  	"github.com/gogf/gf/os/gview"
    21  	"github.com/gogf/gf/util/gvalid"
    22  )
    23  
    24  // Client is a convenience function, which creates and returns a new HTTP client.
    25  func Client() *ghttp.Client {
    26  	return ghttp.NewClient()
    27  }
    28  
    29  // Server returns an instance of http server with specified name.
    30  func Server(name ...interface{}) *ghttp.Server {
    31  	return gins.Server(name...)
    32  }
    33  
    34  // TCPServer returns an instance of tcp server with specified name.
    35  func TCPServer(name ...interface{}) *gtcp.Server {
    36  	return gtcp.GetServer(name...)
    37  }
    38  
    39  // UDPServer returns an instance of udp server with specified name.
    40  func UDPServer(name ...interface{}) *gudp.Server {
    41  	return gudp.GetServer(name...)
    42  }
    43  
    44  // View returns an instance of template engine object with specified name.
    45  func View(name ...string) *gview.View {
    46  	return gins.View(name...)
    47  }
    48  
    49  // Config returns an instance of config object with specified name.
    50  func Config(name ...string) *gcfg.Config {
    51  	return gins.Config(name...)
    52  }
    53  
    54  // Cfg is alias of Config.
    55  // See Config.
    56  func Cfg(name ...string) *gcfg.Config {
    57  	return Config(name...)
    58  }
    59  
    60  // Resource returns an instance of Resource.
    61  // The parameter <name> is the name for the instance.
    62  func Resource(name ...string) *gres.Resource {
    63  	return gins.Resource(name...)
    64  }
    65  
    66  // I18n returns an instance of gi18n.Manager.
    67  // The parameter <name> is the name for the instance.
    68  func I18n(name ...string) *gi18n.Manager {
    69  	return gins.I18n(name...)
    70  }
    71  
    72  // Res is alias of Resource.
    73  // See Resource.
    74  func Res(name ...string) *gres.Resource {
    75  	return Resource(name...)
    76  }
    77  
    78  // Log returns an instance of glog.Logger.
    79  // The parameter <name> is the name for the instance.
    80  func Log(name ...string) *glog.Logger {
    81  	return gins.Log(name...)
    82  }
    83  
    84  // DB returns an instance of database ORM object with specified configuration group name.
    85  func DB(name ...string) gdb.DB {
    86  	return gins.Database(name...)
    87  }
    88  
    89  // Table is alias of Model.
    90  // The database component is designed not only for
    91  // relational databases but also for NoSQL databases in the future. The name
    92  // "Table" is not proper for that purpose any more.
    93  // Deprecated, use Model instead.
    94  func Table(tableNameOrStruct ...interface{}) *gdb.Model {
    95  	return DB().Model(tableNameOrStruct...)
    96  }
    97  
    98  // Model creates and returns a model based on configuration of default database group.
    99  func Model(tableNameOrStruct ...interface{}) *gdb.Model {
   100  	return DB().Model(tableNameOrStruct...)
   101  }
   102  
   103  // Redis returns an instance of redis client with specified configuration group name.
   104  func Redis(name ...string) *gredis.Redis {
   105  	return gins.Redis(name...)
   106  }
   107  
   108  // Validator is a convenience function, which creates and returns a new validation manager object.
   109  func Validator() *gvalid.Validator {
   110  	return gvalid.New()
   111  }