本文整理汇总了Golang中github.com/coreos/coreos-baremetal/bootcfg/server.Server.SelectGroup方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.SelectGroup方法的具体用法?Golang Server.SelectGroup怎么用?Golang Server.SelectGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/coreos-baremetal/bootcfg/server.Server
的用法示例。
在下文中一共展示了Server.SelectGroup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: selectGroup
// selectGroup selects the Group whose selectors match the query parameters,
// adds the Group to the ctx, and calls the next handler. The next handler
// should handle a missing Group.
func (s *Server) selectGroup(core server.Server, next ContextHandler) ContextHandler {
fn := func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
attrs := labelsFromRequest(s.logger, req)
// match machine request
group, err := core.SelectGroup(ctx, &pb.SelectGroupRequest{Labels: attrs})
if err == nil {
// add the Group to the ctx for next handler
ctx = withGroup(ctx, group)
}
next.ServeHTTP(ctx, w, req)
}
return ContextHandlerFunc(fn)
}
示例2: pixiecoreHandler
// pixiecoreHandler returns a handler that renders the boot config JSON for
// the requester, to implement the Pixiecore API specification.
// https://github.com/danderson/pixiecore/blob/master/README.api.md
func (s *Server) pixiecoreHandler(core server.Server) ContextHandler {
fn := func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
// pixiecore only provides a MAC address label
macAddr, err := parseMAC(filepath.Base(req.URL.Path))
if err != nil {
s.logger.Errorf("unparseable MAC address: %v", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
attrs := map[string]string{"mac": macAddr.String()}
group, err := core.SelectGroup(ctx, &pb.SelectGroupRequest{Labels: attrs})
if err != nil {
s.logger.WithFields(logrus.Fields{
"label": macAddr,
}).Infof("No matching group")
http.NotFound(w, req)
return
}
profile, err := core.ProfileGet(ctx, &pb.ProfileGetRequest{Id: group.Profile})
if err != nil {
s.logger.WithFields(logrus.Fields{
"label": macAddr,
"group": group.Id,
}).Infof("No profile named: %s", group.Profile)
http.NotFound(w, req)
return
}
// match was successful
s.logger.WithFields(logrus.Fields{
"label": macAddr,
"group": group.Id,
"profile": profile.Id,
}).Debug("Matched a Pixiecore config")
s.renderJSON(w, profile.Boot)
}
return ContextHandlerFunc(fn)
}
示例3: pixiecoreHandler
// pixiecoreHandler returns a handler that renders the boot config JSON for
// the requester, to implement the Pixiecore API specification.
// https://github.com/danderson/pixiecore/blob/master/README.api.md
func pixiecoreHandler(srv server.Server) ContextHandler {
fn := func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
macAddr, err := parseMAC(filepath.Base(req.URL.Path))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// pixiecore only provides MAC addresses
attrs := map[string]string{"mac": macAddr.String()}
group, err := srv.SelectGroup(ctx, &pb.SelectGroupRequest{Labels: attrs})
if err != nil {
http.NotFound(w, req)
return
}
profile, err := srv.ProfileGet(ctx, &pb.ProfileGetRequest{Id: group.Profile})
if err != nil {
http.NotFound(w, req)
return
}
renderJSON(w, profile.Boot)
}
return ContextHandlerFunc(fn)
}