• 简单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

    在当下的阶段,必将由程序员来主导,甚至比以往更甚。
  • 相关阅读:
    [CareerCup] 11.6 Search a 2D Matrix 搜索一个二维矩阵
    [CareerCup] 11.5 Search Array with Empty Strings 搜索含有空字符串的数组
    [CareerCup] 11.4 Sort the File 文件排序
    [CareerCup] 11.3 Search in Rotated Sorted Array 在旋转有序矩阵中搜索
    VTK 6.3.0 Qt 5.4 MinGW 4.9.1 Configuration 配置
    [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序
    [CareerCup] 11.1 Merge Arrays 合并数组
    Matlab Delete Row or Col 删除矩阵的行或列
    [CareerCup] 10.7 Simplified Search Engine 简单的搜索引擎
    [LeetCode] Nim Game 尼姆游戏
  • 原文地址:https://www.cnblogs.com/randysun/p/15621912.html
Copyright © 2020-2023  润新知