小编Bae*_*ree的帖子

GoLang http网络服务器提供视频(mp4)

我使用golang开发了一个webserver.漂亮的飞机东西,它只提供html/js/css和图像,它们完美无缺:

func main() {
    http.Handle("/", new(viewHandler))
    http.ListenAndServe(":8080", nil)
}

func (vh *viewHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    path := r.URL.Path[1:]
    log.Println(path)
    data, err := ioutil.ReadFile(string(path))

    if err == nil {

        var contentType string

        if strings.HasSuffix(path, ".html") {
            contentType = "text/html"
        } else if strings.HasSuffix(path, ".css") {
            contentType = "text/css"
        } else if strings.HasSuffix(path, ".js") {
            contentType = "application/javascript"
        } else if strings.HasSuffix(path, ".png") {
            contentType = "image/png"
        } else if strings.HasSuffix(path, ".jpg") {
            contentType = "image/jpeg"
        } 

        w.Header().Add("Content-Type", contentType)
        w.Write(data) …
Run Code Online (Sandbox Code Playgroud)

mp4 webserver http go html5-video

9
推荐指数
1
解决办法
5303
查看次数

Angular 5服务更换/覆盖

我为我的项目创建了一个包含一些组件和服务的核心库.我用ng-packagr构建了库.在引用库的消费项目中,我构建了包含库提供的组件的webapp.到目前为止没什么特别的.但有时我想要一个组件(来自我的lib)从lib外部的服务调用一个方法.这可能吗?我可以以某种方式将服务注入到库中定义的组件吗?

干杯

javascript angular-cli angular ng-packagr angular5

5
推荐指数
1
解决办法
4299
查看次数

ng内的Angular 6 ngTemplateOutlet用于多个上下文

假设我具有以下组件:

@Component({
  selector: 'todo-lib',
  template: `
<li *ngFor="let todo of libService.todos">
  <div class="view">
    <label>{{todo.title}}</label>
    <ng-container *ngTemplateOutlet="incomingTemplate;context:ctx"></ng-container>
  </div>
</li>

<ng-template #incomingTemplate let-service="templateService">
<button (click)="service.removeTodo(todo)">delete</button>
</ng-template>
`,
  styles: []
})
export class TodoLibComponent implements OnInit {

  ctx = {
    templateService: this.libService
  };
Run Code Online (Sandbox Code Playgroud)

待办事项列表在libService内部。我不会在这里发布它,因为它的逻辑无关紧要。“ ng-template”将从另一个组件中注入,并将删除按钮添加到我的待办事项列表中。这意味着:通常没有删除选项,除了将提供“ ng-template”

但是,此方法将失败,并出现以下错误:

message: "_v.context.todo is undefined"
Run Code Online (Sandbox Code Playgroud)

由于“ todo”不是上下文对象“ ctx”的一部分,因此无法访问它。为了实现这一点,我将被迫这样做:

<ng-container *ngTemplateOutlet="incomingTemplate;context:{ todo: todo}">
Run Code Online (Sandbox Code Playgroud)

这将允许我访问待办事项对象,但不再访问服务。

看来我无法同时访问ngFor AND和在ctx属性中定义的服务定义的todo属性。是否有解决方案来实现两者?

干杯

ngfor angular angular6

4
推荐指数
1
解决办法
5354
查看次数

什么是MSpec与Visual Studio集成的替代工具?

我最近完成了一个C#项目,并使用Machine.Fakes在MSpec上编写了测试.我一直在使用命令行运行器.在Visual Studio中查看测试结果/运行会更舒服.但是,ReSharper不在我的预算之内.有吸引力的选择吗?

c# resharper mspec

2
推荐指数
1
解决办法
1334
查看次数