zoukankan      html  css  js  c++  java
  • 简单web

    简单web

    image-20211108085431850

    一、hello web

    package main
    
    import (
    	"fmt"
    	"net/http"
    )
    
    /*
    @author RandySun
    @create 2021-11-08-22:42
    */
    
    func sayHello(w http.ResponseWriter, r *http.Request) {
    	_, _ = fmt.Fprintln(w, "hello web")
    
    }
    func main() {
    	http.HandleFunc("/hello", sayHello)
    	err := http.ListenAndServe(":9999", nil)
    	if err != nil {
    		fmt.Printf("http server failed err:%#v", err)
    	}
    	
    }
    
    

    image-20211108224950141

    二、插入html

    package main
    
    import (
    	"fmt"
    	"net/http"
    )
    
    /*
    @author RandySun
    @create 2021-11-08-22:42
    */
    
    func sayHello(w http.ResponseWriter, r *http.Request) {
    	_, _ = fmt.Fprintln(w, "<H1>hello web</H1>")
    	_, _ = fmt.Fprintln(w, "<H1 style='color: red'>hello web</H1>")
    
    }
    func main() {
    	http.HandleFunc("/hello", sayHello)
    	err := http.ListenAndServe(":9999", nil)
    	if err != nil {
    		fmt.Printf("http server failed err:%#v", err)
    	}
    
    }
    
    

    image-20211108225804450

    三、读取文件渲染

    // helloWeb.txt
    
    <h1 style="color:red">hello web</h1>
    <h2>hello web</h2>
    <img id="randy" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1114%2F0512210S939%2F2105120S939-12-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638976149&t=ab8df8adcb0ce26f03170766e7744d94">
    
    <button id="sun">点我</button>
    <script>
       document.getElementById("sun").onclick=function(){
            document.getElementById("randy").src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2F12%2F1f%2Fa0%2F121fa0f4730a034237c13b7595db3a16.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638976181&t=125bfc28da1fb97e6fe5e179fdead261"
       }
    </script>
    
    
    package main
    
    import (
    	"fmt"
    	"io/ioutil"
    	"net/http"
    )
    
    /*
    @author RandySun
    @create 2021-11-08-22:42
    */
    
    func sayHello(w http.ResponseWriter, r *http.Request) {
    	_, _ = fmt.Fprintln(w, "<H1>hello web</H1>")
    	_, _ = fmt.Fprintln(w, "<H1 style='color: red'>hello web</H1>")
    
    }
    
    func sayHelloFile(w http.ResponseWriter, r *http.Request) {
    
    	b, _ := ioutil.ReadFile("G:\\goproject\\go\\bubble\\demo\\01httpTest\\helloWeb.txt")
    	a, _ := fmt.Fprintln(w, string(b))
    	fmt.Println(a)
    
    }
    func main() {
    	http.HandleFunc("/hello", sayHello)
    	http.HandleFunc("/helloFile", sayHelloFile)
    	err := http.ListenAndServe(":9999", nil)
    	if err != nil {
    		fmt.Printf("http server failed err:%#v", err)
    	}
    
    }
    
    

    image-20211108231235255

    image-20211108213848772

    在当下的阶段,必将由程序员来主导,甚至比以往更甚。
  • 相关阅读:
    微软外服 AlI In One
    js 循环多次和循环一次的时间的性能对比 All In One
    vue inject All In One
    Excel 表格数据倒置 All In One
    SVG tickets All In One
    OH MY ZSH All In One
    js array for loop performance compare All In One
    mac terminal show You have new mail All In one
    新闻视频 26 制作母版页
    转自牛腩 母版页和相对路径
  • 原文地址:https://www.cnblogs.com/randysun/p/15621912.html
Copyright © 2011-2022 走看看